1

I have a large number of photos that are contained in over 100 directories. These are all pre-installation photos. I would like to keep the existing directory structure but add a \pre and \post directory in any directory that contains a .jpg photo. I dont want a subdirectory created if a given directory only contains other directories but not files

For testing , I have a single .jpg in c:\temp\one\two\three. I ran this command in c:\temp:

FOR /R c:\temp %G IN (*.jpg) DO mkdir pre 

However, it created the pre directory directly under c:\temp

1 Answer 1

2

So, the problem is that you try to mkdir in a current dir. For each JPG file you find you want to get a directory name, switch to it (using pushd), create a pre directory if it does not exist yet, and then switch back to where you started (with popd).

FOR /R c:\temp %G IN (*.JPG) DO pushd %~dpG && if not exist pre mkdir pre && popd 
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! That worked perfectly on my test data. Before running it on a copy of my actual data I'll read through the very helpful links you included to do my best understand why your solution works

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.