?
Solved

MS DOS Batch File to Rename & Move Files from nested file structure

Posted on 2008-01-31
4
Medium Priority
?
4,335 Views
Last Modified: 2010-04-21
Hello,

I would like to modify the following code to recursively move files from c:\pictures to here c:\new pictures and rename them pre-fixed with their sub folder name, can anyone help?

Thanks

@echo off
 
setlocal
 
pushd "c:\pictures"
 
for /f "tokens=*" %%a in ('dir /b /a-d /s *.jpg') do copy "%%a" "c:\new pictures"
 
popd

Open in new window

0
Comment
Question by:SickBoy23
  • 3
4 Comments
 
LVL 30

Accepted Solution

by:
SteveGTR earned 2000 total points
ID: 20787649
You could try this. I've disabled the copy command so that it is echoed out. To do the actual copy you would remove the echo command from the 2nd for statement. I've commented the line for you:
@echo off
 
setlocal
 
pushd "c:\" 
 
call :PROCESS "pictures"
 
popd
 
goto :EOF
 
:PROCESS
 
pushd "%~1"
 
for /f "tokens=*" %%a in ('dir /b /ad 2^>NUL') do call :PROCESS "%%a"
 
REM ** Remove echo from this line to actually do the copy
for /f "tokens=*" %%a in ('dir /b /a-d *.jpg 2^>NUL') do echo copy "%%a" "c:\new pictures\%~1_%%a"
 
popd
 
goto :EOF

Open in new window

0
 

Author Closing Comment

by:SickBoy23
ID: 31426765

Steve the code works great!! Appreciated!

Thanks
0
 

Author Comment

by:SickBoy23
ID: 20795127

Steve, if I want to change the paths e.g. move & rename the contents of C:\Temp\NewFolder\Pics to here C:\Temp\NewFolder, how would I do this?

Thanks
0
 

Author Comment

by:SickBoy23
ID: 20795155

Ignore the above figured it out, I was doing something stupid!
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Issue: Unstable cursor in Windows XP and Windows runs extremely slow in that any click will bring up the Hour glass (sometimes for several seconds before giving you what you want) . Troubleshooting Process and the FINAL FIX: This issue see…
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question