Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Batch File to work with gaps


  • Please log in to reply
7 replies to this topic

#1 OldNick

OldNick

  • Members
  • 9 posts
  • OFFLINE
  •  
  • Local time:11:35 AM

Posted 16 March 2009 - 02:11 AM

I want to copy all files from one folder to another, by dragging and dropping the source folder onto a batch file.

copy "%1%\*.*" c:\nickdocs\*.*

However if there is a gap in the path name or or folder name of the source, the batch file says "The system cannot find the file specified"

For instance if I use c:\Input 1 as my source, the result is

""C:\Input 1"\nickdocs\*.*
"The system cannot find the file specified"

and there it ends

Can anyone point me with this?

Thanks for any help

Nick

BC AdBot (Login to Remove)

 


#2 Romeo29

Romeo29

    Learning To Bleep


  • Members
  • 3,194 posts
  • OFFLINE
  •  
  • Gender:Not Telling
  • Location:127.0.0.1
  • Local time:11:35 AM

Posted 17 March 2009 - 05:40 AM

You should place one more set of inverted commas (" "). For example,

copy ""%1\*.*""  c:\nickdocs\*.*


#3 OldNick

OldNick
  • Topic Starter

  • Members
  • 9 posts
  • OFFLINE
  •  
  • Local time:11:35 AM

Posted 17 March 2009 - 05:48 AM

Thanks for that!

I _thought_ I had tried that, but I will give it a go.

Lettyano.

Nick

#4 OldNick

OldNick
  • Topic Starter

  • Members
  • 9 posts
  • OFFLINE
  •  
  • Local time:11:35 AM

Posted 17 March 2009 - 06:04 AM

Nope. that did not help.

#5 M...

M...

  • Members
  • 386 posts
  • OFFLINE
  •  
  • Local time:08:35 AM

Posted 17 March 2009 - 12:18 PM

Hello OldNick,

In this case, I think you want the following line in your batch file:

copy %1\*.* c:\nickdocs\*.*
1. If the name of the folder/directory you're dragging to the batch file does not contain any spaces (e.g., "ABC"), the command will expand to:

copy C:\ABC\*.* c:\nickdocs\*.*

which is what you want.

2. If the name of the folder/directory you're dragging to the batch file does contain spaces (e.g., "ABC 123 XYZ"), the command will expand to:

copy "C:\ABC 123 XYZ"\*.* c:\nickdocs\*.*

which does work. Evidently, in the process of dragging a folder name containing spaces to your batch file, the system automatically supplies the surrounding quotes if it detects that the folder name (argument to the batch file) contains any spaces.

Also note that the command, as written above, will copy only the top-level files -- it will not copy any subfolders.

#6 Romeo29

Romeo29

    Learning To Bleep


  • Members
  • 3,194 posts
  • OFFLINE
  •  
  • Gender:Not Telling
  • Location:127.0.0.1
  • Local time:11:35 AM

Posted 17 March 2009 - 02:34 PM

Posted Image

It appears you are doing something wrong...

#7 OldNick

OldNick
  • Topic Starter

  • Members
  • 9 posts
  • OFFLINE
  •  
  • Local time:11:35 AM

Posted 17 March 2009 - 04:12 PM

So it would appear. BUT now I am being told to both add "" and to take them away.

You can see my code. So _what_ am I doping wrong?

#8 M...

M...

  • Members
  • 386 posts
  • OFFLINE
  •  
  • Local time:08:35 AM

Posted 17 March 2009 - 05:18 PM

In this case (dragging and dropping), either one will work.

In the screen snapshot below, the first "copy" command shows the expansion and execution of the version I posted above. The second "copy" command shows the expansion and execution of the version posted by Romeo29 above:

http://img14.imageshack.us/img14/6969/scrn003.png




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users