Create subdirectory under each directory containing a file

假如想象 提交于 2020-03-23 12:01:35

问题


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:


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


来源:https://stackoverflow.com/questions/60540370/create-subdirectory-under-each-directory-containing-a-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!