Moving files into new subdirectory, except for existing folders?

房东的猫 提交于 2021-02-11 12:05:28

问题


A Redditor had written me a great script that allowed me to move all the files in a series of folders into a new subdirectory in all those folders called New. However, I also have pre-existing folders (namely just 1 called "Journals") that have had their files moved into a subdirectory called New, as well.

How would I modify the following script (on Windows) to not touch any folders within the folders, or perhaps not touch any folder called Journals?

For example, the current directory looks like:

Parent/Folder name/tons of files/
Parent/Folder name/Journals/tons of files

(folder name = random string of alphanumeric numbers in the thousands). Each folder has a ton of files, and a folder called Journals.

I would like:

Parent/randomstring folder/New/tons of files/
Parent/randomstring folder/Journals/tons of files

The code they wrote for me:

# Run from search root
cd "O:\..."
# Change this to taste
export NEWDIR=New

find . | egrep '(mp4$|jpg$|png$)' |
while read FILE
do

BASEDIR=$(dirname "$FILE")
mkdir "$BASEDIR/$NEWDIR" > /dev/null 2>&1
mv "$FILE" "$BASEDIR/$NEWDIR"

done

This code would do the following:

Parent/randomstring folder/New/tons of files/
Parent/randomstring folder/Journals/new/tons of files

来源:https://stackoverflow.com/questions/61534732/moving-files-into-new-subdirectory-except-for-existing-folders

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