Copy Files from Text List with spaces [Solved/Closed]

Hercules - Feb 26, 2009 at 07:33 AM - Latest reply:  the SASS Man
- Sep 9, 2010 at 07:48 PM
Hello,

I am trying to create a batch file to copy files from a list of locations in a .txt file to a new location.

The code below gives me an error, because the files have spaces in the names.

@echo off
echo -- > C:\TestingTMP.txt
xcopy /y C:\Testing.m3u C:\TestingTMP.txt
find "H:\Music" C:\TestingTMP.txt >> C:\Testing.txt
for /f %%a in (C:\Testing.txt) do (
xcopy /y %%a H:\Music\Testing
)

"Testing.txt":
H:\Music\Kutless\Kutless - Sea Of Faces.mp3
H:\Music\Tree 63\The Life And Times Of Absolute - Tree 63 - How Did I Sleep.mp3
etc.

Using a third party program (because all the forums indicate this is what it will take to do text find and replace), I have changed the list generated in "Testing.txt" and put inverted comma's around the files with spaces.

H:\"Music"\"Kutless"\"Kutless - Sea Of Faces".mp3
H:\"Music"\"Tree 63"\"The Life And Times Of Absolute - Tree 63 - How Did I Sleep".mp3
etc.

Now the code
for /f %%a in (C:\Testing.txt) do (
xcopy /y %%a H:\Music\Testing
gives me a "Parse Error"! And it still only looks at the title before the first space!
eg.
c:\>(xcopy /y H:\"Music"\"Kutless"\"Kutless - Sea H:\Music\Testing
Parse Error

Can anyone please shed some light on this supposed to be simple function and how to solve the problem?
See more 

5 replies

Best answer
athenazob 5 Posts Tuesday September 16, 2008Registration date February 27, 2009 Last seen - Feb 27, 2009 at 01:41 AM
8
Thank you
hi,
in fact you should use your original list and modify the "For /F" statement as written downwards:

for /F "delims=" %%a in (C:\Testing.txt) do (
xcopy /Y "%%a" H:\Music\Testing
)


hope it helps you.

Thank you, athenazob 8

Something to say? Add comment

CCM has helped 1806 users this month

the SASS Man - Sep 9, 2010 at 07:12 PM
1
Thank you
All you should really have to do is, put quotes around the filename itself in the XCopy command....link so:

xcopy /y "%%a" H:\Music\Testing

That way, whether the filenames have spaces or not, Windows will expand "%%a" to "Your Filename.ext", and the copy should work perfectly.

Cheers!
the SASS Man - Sep 9, 2010 at 07:42 PM
1
Thank you
Oh, one more thing....in order to get past the "Tokenizing" process of the For command, you MUST use the following option:

/F "delimeter="

This tells the system that the ENTIRE LINE from your source file is a single "token" to be passed to the command(s) inside the parenthesis. For's default behavior is to basically treat every space and tab character it finds as the equivalent as an EOL character. Unless the user defines some special way of parcing the line.

you can get more information, including info specific to your operating system, by typing "help for" at the command line.

Cheers!
Bleach! My fingers are faster than my brain ATm....

That option is:

/F "delims="

Only Microsoft could make a less intuitive operating system....trust me.
0
Thank you
You might try using PullaFile. Here is the link: www.pullafile.com