Page 1 of 1

FOR usage to copy from list file

Posted: 29 Mar 2016 15:56
by drgt
Hi
I tried to search for the FOR usage

How to copy a set of files listed in FileList.txt using the FOR command both directly from the command prompt and from a batch file?

Are there any limitations in language, spaces etc in the file names contained in FileList.txt?

Thank you.

Re: FOR usage to copy from list file

Posted: 29 Mar 2016 18:15
by ShadowThief
You'd want to use for /f for that. See FOR_F on SS64 for more.

In the command prompt

Code: Select all

for /f "delims=" %A in (FileList.txt) do (
    copy "%A" "C:\path\to\wherever\you're\putting\them\and also this is in quotes because it's 2016 and people still put spaces in their paths\omg"
)


edited:

In a script (same thing, but %%A instead of %A)

Code: Select all

for /f "delims=" %%A in (FileList.txt) do (
    copy "%%A" "C:\path\to\wherever\you're\putting\them\and also this is in quotes because it's 2016 and people still put spaces in their paths\omg"
)

Re: FOR usage to copy from list file

Posted: 30 Mar 2016 06:29
by drgt
Thanks a lot !!!

I take it this "%A%" is a typo?

Re: FOR usage to copy from list file

Posted: 30 Mar 2016 10:14
by ShadowThief
What %A%?

%A (with one %) is used on the command prompt, %%A (with two consecutive %s) is used in scripts.

Re: FOR usage to copy from list file

Posted: 30 Mar 2016 13:52
by foxidrive
There was one there - a typo. The autocorrecting software on the Dostips forum fixed it.

Re: FOR usage to copy from list file

Posted: 30 Mar 2016 13:55
by drgt
Thanks.
How can I mark this SOLVED?