Need help with a batch script!!!
Page 1 of 1
proddan




Posts: 1066
Location: Gulf of Aden
PostPosted: Tue, 17th Jan 2012 08:25    Post subject: Need help with a batch script!!!
Hi,

Need help with a batch script..

I need to move .pdf files from multipel folders with different names to one archive folder

example:

c:\temp\pdf\1
c:\temp\pdf\2
c:\temp\pdf\3
c:\temp\pdf\4
c:\temp\pdf\5

to

c:\temp\archive\pdf\1
c:\temp\archive\pdf\2
c:\temp\archive\pdf\3
c:\temp\archive\pdf\4
c:\temp\archive\pdf\5


I have tried the move script but this will only move .pdf files from one folder. I need to move the pdf files from multiple folders witrh different names. I want the script to search for subfolders under "c:\temp\archive\pdf" and copy the folder names and move the pdf files to an archive folder

move /-y c:\temp\pdf\1 \*.*.pdf" "c:\temp\archive\pdf\1"
Back to top
shole




Posts: 3363

PostPosted: Tue, 17th Jan 2012 13:11    Post subject:
you need a for loop
http://www.robvanderwoude.com/for.php

*.*.pdf doesn't do anything
use folder\ on target so you don't accidentally move a folder and overwrite the old one containing all the pdfs, if a folder name happens to match your source filename

Code:

for %%f in ("c:\temp\pdf\*") do move /-y "c:\temp\pdf\%%~nf\*.pdf" "c:\temp\archive\pdf\%%~nf\"

this does it for every folder under c:\temp\pdf\
~n strips the path from the variable so it's only the local name
http://ss64.com/nt/syntax-args.html

Code:

for %%f in (1 2 3 4 5) do move /-y "c:\temp\pdf\%%f\*.pdf" "c:\temp\archive\pdf\%%f\"

this will work for your specific case
essentially it's the same as above, but the list is generated manually as numbers

haven't tested these but they should work fine
Back to top
shole




Posts: 3363

PostPosted: Tue, 17th Jan 2012 13:17    Post subject:
if you need to add folder creation for the archive in the generic example you can do this
Code:

for %%f in ("c:\temp\pdf\*") do (
   mkdir "c:\temp\archive\pdf\%%~nf"
   move /-y "c:\temp\pdf\%%~nf\*.pdf" "c:\temp\archive\pdf\%%~nf\")

i think the batch fails if the closing ) is alone on the last row, which is annoying for a programmer who likes things tidy
just something to keep in mind
Back to top
Page 1 of 1 All times are GMT + 1 Hour
NFOHump.com Forum Index - Operating Systems
Signature/Avatar nuking: none (can be changed in your profile)  


Display posts from previous:   

Jump to:  
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 vote in polls in this forum


Powered by phpBB 2.0.8 © 2001, 2002 phpBB Group