BleepingComputer.com: Batch File to work with gaps

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Batch File to work with gaps

#1 User is offline   OldNick 

  • New Member
  • Pip
  • Find Topics
  • Group: Members
  • Posts: 9
  • Joined: 02-August 05

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

#2 User is offline   Romeo29 

  • Learning To Bleep
  • PipPipPipPipPipPip
  • Find Topics
  • Group: BC Advisor
  • Posts: 2,834
  • Joined: 06-July 08
  • Gender:Not Telling
  • Location:127.0.0.1

Posted 17 March 2009 - 05:40 AM

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

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


#3 User is offline   OldNick 

  • New Member
  • Pip
  • Find Topics
  • Group: Members
  • Posts: 9
  • Joined: 02-August 05

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 User is offline   OldNick 

  • New Member
  • Pip
  • Find Topics
  • Group: Members
  • Posts: 9
  • Joined: 02-August 05

Posted 17 March 2009 - 06:04 AM

Nope. that did not help.

#5 User is offline   M... 

  • Senior Member
  • PipPipPipPip
  • Find Topics
  • Group: Members
  • Posts: 362
  • Joined: 02-June 07

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 User is offline   Romeo29 

  • Learning To Bleep
  • PipPipPipPipPipPip
  • Find Topics
  • Group: BC Advisor
  • Posts: 2,834
  • Joined: 06-July 08
  • Gender:Not Telling
  • Location:127.0.0.1

Posted 17 March 2009 - 02:34 PM


#7 User is offline   OldNick 

  • New Member
  • Pip
  • Find Topics
  • Group: Members
  • Posts: 9
  • Joined: 02-August 05

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 User is offline   M... 

  • Senior Member
  • PipPipPipPip
  • Find Topics
  • Group: Members
  • Posts: 362
  • Joined: 02-June 07

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

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users