DosTips.com

A Forum all about DOS Batch
It is currently 24 Jun 2017 13:11

All times are UTC-06:00




Post new topic  Reply to topic  [ 29 posts ]  Go to page 1 2 Next
Author Message
PostPosted: 04 Jan 2017 09:30 
Offline

Joined: 21 Sep 2010 02:22
Posts: 96
Please help me with the syntax of:

copy every file in dir c:\a\b\c /a-d /on /b to c: \d\e\f

both in command line and batch.

Alternatively, copy every file in c:\a\b\c\filelist.txt from c:\d\e\f to c:\g\h\i

Thank you


Top
   
PostPosted: 04 Jan 2017 10:29 
Offline

Joined: 21 Mar 2014 08:50
Posts: 409
Possibly…
Code: Select all
Copy C:\a\b\c\*.* C:\d\e\f
…if you need something else please explain it better.


Top
   
PostPosted: 04 Jan 2017 11:42 
Offline

Joined: 16 Dec 2016 22:31
Posts: 98
For the second one use this(untested)
Code: Select all
for /f %%a in ("c:/a/b/c/filelist.txt") do (
 cd "c:/d/e/f"
 if exists %%a copy %%a "c:/g/h/i"
)


Sounak


Top
   
PostPosted: 04 Jan 2017 13:26 
Offline
Expert

Joined: 23 Dec 2011 13:59
Posts: 3507
Sounak@9434 wrote:
For the second one use this(untested)
Code: Select all
for /f %%a in ("c:/a/b/c/filelist.txt") do (
 cd "c:/d/e/f"
 if exists %%a copy %%a "c:/g/h/i"
)


Sounak

You might want to account for spaces in file names.


Top
   
PostPosted: 04 Jan 2017 22:34 
Offline

Joined: 21 Sep 2010 02:22
Posts: 96
Compo wrote:
Possibly…
Code: Select all
Copy C:\a\b\c\*.* C:\d\e\f
…if you need something else please explain it better.


The difference between copy every file in dir c:\a\b\c /a-d /on /b to c: \d\e\f AND
Code: Select all
Copy C:\a\b\c\*.* C:\d\e\f
is that the latter will copy the files in "disk order" while the requirement is that they be copied in alphabetical order that the dir command specifies.

Of course, the dir command can be redirected to create a filelist.txt and then use that to carry out the copying in the order that the file dictates.
I thought there might be a way to skip the creation of the filelist.txt and do it all in one like
Code: Select all
for /f %%a in dir....


Top
   
PostPosted: 04 Jan 2017 22:45 
Offline

Joined: 16 Dec 2016 22:31
Posts: 98
Squashman wrote:
Sounak@9434 wrote:
For the second one use this(untested)
Code: Select all
for /f %%a in ("c:/a/b/c/filelist.txt") do (
 cd "c:/d/e/f"
 if exists %%a copy %%a "c:/g/h/i"
)


Sounak

You might want to account for spaces in file names.

Thanks Squashman, new code(untested):-
Code: Select all
for /f "delims=" %%a in ("c:/a/b/c/filelist.txt") do (
 cd "c:/d/e/f"
 if exists "%%a" copy "%%a" "c:/g/h/i"
)


Sounak


Last edited by Sounak@9434 on 05 Jan 2017 01:26, edited 1 time in total.

Top
   
PostPosted: 04 Jan 2017 23:24 
Offline

Joined: 21 Sep 2010 02:22
Posts: 96
Sounak@9434 wrote:
Thanks Squashman, new code(untested):-
Code: Select all
for /f "delims=" %%a in ("c:/a/b/c/filelist.txt") do (
 cd "c:/d/e/f"
 if exists %%a copy %%a "c:/g/h/i"
)


Sounak


Why not using backslashes?

Result (not related to above question):
Code: Select all
%a was unexpected at this time


Top
   
PostPosted: 05 Jan 2017 01:10 
Offline

Joined: 16 Dec 2016 22:31
Posts: 98
drgt wrote:
Why not using backslashes?

You mean using backslash as delimiter?


Top
   
PostPosted: 05 Jan 2017 01:24 
Offline

Joined: 21 Sep 2010 02:22
Posts: 96
I mean you use c:/a/b/c/filelist.txt instead of c:\a\b\c\filelist.txt


Top
   
PostPosted: 05 Jan 2017 02:15 
Offline

Joined: 16 Dec 2016 22:31
Posts: 98
drgt wrote:
I mean you use c:/a/b/c/filelist.txt instead of c:\a\b\c\filelist.txt

Sorry, I should have posted it from my pc(android is tricky for typing codes) though yeah my fault. Fixed one here:-

Code: Select all
for /f "delims=" %%a in ("c:\a\b\c\filelist.txt") do (
 cd "c:\d\e\f"
 if exist "%%a" copy "%%a" "c:\g\h\i"
)

Thanks drgt for pointing that out.

Sounak


Top
   
PostPosted: 05 Jan 2017 02:59 
Offline

Joined: 21 Sep 2010 02:22
Posts: 96
Sounak@9434 wrote:
Thanks drgt for pointing that out.

Sounak


Never mind!

Lets see if someone has the answer to:
drgt wrote:
The difference between copy every file in dir c:\a\b\c /a-d /on /b to c: \d\e\f AND
Code: Select all
Copy C:\a\b\c\*.* C:\d\e\f
is that the latter will copy the files in "disk order" while the requirement is that they be copied in alphabetical order that the dir command specifies.

Of course, the dir command can be redirected to create a filelist.txt and then use that to carry out the copying in the order that the file dictates.
I thought there might be a way to skip the creation of the filelist.txt and do it all in one like
Code: Select all
for /f %%a in dir....


***That is why the title is "For ... including DIR


Top
   
PostPosted: 05 Jan 2017 08:16 
Offline

Joined: 16 Dec 2016 22:31
Posts: 98
drgt wrote:
I thought there might be a way to skip the creation of the filelist.txt and do it all in one like
Code: Select all
for /f %%a in dir....


***That is why the title is "For ... including DIR

In this case you are talking about the first request. Yeah the code can be achived by directly redirecting the output of dir command using 'singlequote'(maybe with usebackq and "double quote" for file name with spaces).

Sounak


Top
   
PostPosted: 05 Jan 2017 23:52 
Offline

Joined: 21 Sep 2010 02:22
Posts: 96
Can you be more specific please?


Top
   
PostPosted: 06 Jan 2017 00:10 
Offline

Joined: 16 Dec 2016 22:31
Posts: 98
I am just replying based on the command you said earlier 'dir c:\a\b\c /a-d /on /b'
Code: Select all
for /f "delims=" %%a in ('dir c:\a\b\c /a-d /on /b') do (
   copy "%%a" "c:\d\e\f"
)


Top
   
PostPosted: 06 Jan 2017 02:58 
Offline

Joined: 21 Mar 2014 08:50
Posts: 409
drgt wrote:
The difference between copy every file in dir c:\a\b\c /a-d /on /b to c: \d\e\f AND
Code: Select all
Copy C:\a\b\c\*.* C:\d\e\f
is that the latter will copy the files in "disk order" while the requirement is that they be copied in alphabetical order that the dir command specifies.

If you are only performing a copy, and one which will happen relatively quickly, why would the order matter? If I was copying the content of a script on here, the end product would look exactly the same if copied it from bottom to top or the opposite.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 29 posts ]  Go to page 1 2 Next

All times are UTC-06:00


Who is online

Users browsing this forum: Bing [Bot] and 12 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited