I have a directory full of folders whose subfolders each contain a .xml file. They are all supposed to be named apple.xml but unfortunately, they each have different names such as apple_1.xml or appleTEST.xml and other unique variations that don't follow a specific pattern. Luckily, there is only one .xml file per folder.
I was hoping there was a way to use Applescript to search an entire directory and all of its folders for files with the .xml extension and rename them all to just apple.xml?
Thanks
IFS=; while read -r f; do echo mv -v "$f" "${f%/*}/apple.xml"; done <<< "$(find "/path/to/parent_XML_dir" -type f -iname '*.xml')"while changing"/path/to/parent_XML_dir"to the proper pathname. Run it the first time still with theechocommand in front of themvcommand to see what themvcommand would look like. If you like the output, remove theechocommand and run it again to rename the files. NOTE: Always insure you have a backup before running commands that modify the filesystem! - user3439894-print0option withfindto ensure each pathname is delimited with a NUL byte (\0) before redirecting to awhileloop. To read the NUL char in awhileloop add the-d ''option toread. E.g.:while IFS= read -rd '' f; do echo mv -v "$f" "${f%/*}/apple.xml"; done < <(find "/path/to/parent_XML_dir" -type f -iname '*.xml' -print0)- RobCmkdir -p ~/Desktop/foo/{a..c} && touch ~/Desktop/foo/{a..b}/apple_1.xml && touch ~/Desktop/foo/c/$'apple\napple.xml'- note in foldercthe multi-line filename. 2. Run your cmd:IFS=; while read -r f; do mv -v "$f" "${f%/*}/apple.xml"; done <<< "$(find ~/Desktop/foo -type f -iname '*.xml')"- note, the file in folder c` has not been renamed. 3. Clean up, runrm -rf ~/Desktop/fooand repeat point 1. 4. Runwhile IFS= read -rd '' f; do mv -v "$f" "${f%/*}/apple.xml"; done < <(find ~/Desktop/foo -type f -iname '*.xml' -print0)- RobC