This is needed due to total sloppiness by some users. In a directory resource for a database, many of the folders contain nothing but the letters A - Z as alphabetized sub-folders.
Files put in folders of this type are SUPPOSED to be put inside the correct Alphabetic subfolder like a filing cabinet. But... They often are not.
Over a period of a few weeks, I can have as many as 100 loose files that the DB that LOOKS for them under the alphabetic sub-folder they belong in.
"Alexander, John.pdf" should have gone in the "A" subdirectory inside the parent folder but instead he shows up outside the sub-folder in the parent. This usually occurs in large groups. I have yet to figure out which of the people loading this cannot read the alphabet but someone can't!
The next person to use the DB software, it brings up a "no record found" because the DB software is looking under A or B or C subfolders
So far, I have been moving these by hand to the correct subdirectories when they start to pile up in each parent folder but there must be some way automatically scan these loose files and move all of them into the correct sub-folder based on the first letter of their last name. (usual format last name, first name).
Thanks if you have an easy to run script! It should process all loose files in a directory moving them into the correct subdirectory based on the first letter in the filename Note: 0 - 9 are considered to be under A as there are so few
ALSO note: I have been trying scripts from another site worded like this>
$ mkdir -p output/{A..Z}; for i in tstdir/*; do export FILE=$(basename "$i"); LTR=$(echo" ${FILE:0:1}" | tr [a-z] [A-Z]); mv "$i" "output/$LTR/$FILE" ; done
<or>
$ mkdir -p output/{A..Z}
$ for i in tstdir/*; do
FILE=$(basename "$i")
LTR=$(echo "${FILE:0:1}" | tr [a-z] [A-Z])
mv "$i" "output/$LTR/$FILE"
done
But not getting there. And as I mention next, the ultimate would be to make the directory "self-adjusting" to prevent anyone from even being able to put a file out loose in it to start with.