Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .