0

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?

1 Answer 1

0

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"

You must log in to answer this question.

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