FOR usage to copy from list file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
drgt
Posts: 160
Joined: 21 Sep 2010 02:22
Location: Greece

FOR usage to copy from list file

#1 Post by drgt » 29 Mar 2016 15:56

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.

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: FOR usage to copy from list file

#2 Post by ShadowThief » 29 Mar 2016 18:15

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"
)

drgt
Posts: 160
Joined: 21 Sep 2010 02:22
Location: Greece

Re: FOR usage to copy from list file

#3 Post by drgt » 30 Mar 2016 06:29

Thanks a lot !!!

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

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: FOR usage to copy from list file

#4 Post by ShadowThief » 30 Mar 2016 10:14

What %A%?

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

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: FOR usage to copy from list file

#5 Post by foxidrive » 30 Mar 2016 13:52

There was one there - a typo. The autocorrecting software on the Dostips forum fixed it.

drgt
Posts: 160
Joined: 21 Sep 2010 02:22
Location: Greece

Re: FOR usage to copy from list file

#6 Post by drgt » 30 Mar 2016 13:55

Thanks.
How can I mark this SOLVED?

Post Reply