Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am moving .jpg files from a directory and its subdirectories on a daily basis and then deleting them. To make this easier I created 2 batch files: One that moves the files and one that deletes them.

To move the files:

move C:\"DIRECTORY\*.jpg C:\temp\
move C:\"DIRECTORY\SUBDIRECTORY\*.jpg C:\temp\
move C:\"DIRECTORY\SUBDIRECTORY2\*.jpg C:\temp\
move C:\"DIRECTORY\SUBDIRECTORY3\*.jpg C:\temp\

And to delete files:

del C:\temp\*.jpg

Can I create one script that looks for the files under the folder and subfolders (new subfolders are created regularly) that can do both?

share|improve this question

1 Answer 1

I don't get it. Are you doing something in between moving the .JPGs to Temp and deleting them? If not, why not simply delete them instead of moving and then deleting? Here's a command that will do just that:

for /r "Drive:\Path to\source folder" %f in (*.jpg) do @del "%f"

If you want to do it in two steps with other actions in between, use this:

for /r "Drive:\Path to\source folder" %f in (*.jpg) do @move "%f" "Drive:\Path to\destination folder"
REM Do something else here
del "Drive:\Path to\destination folder\*.jpg"
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.