Move files into folder named according to file's extension

Hi, last time I brought this subject up with Leo, I think I confused him and other people about my need. To explain in more detail, every day I receive many emails most with an array of email attachments. These attachments of various types of files i.e. different extension types. At this point of time, the expedient way to deal with these attachments is to simply detach them and dump them into the correct project directory (assuming the sender has provided a subject to his email). On my system, each project is asigned to a project directory folder. Each project folder is numerically named i.e. year and job number within that year. For example, the 10th job in 2016 would be named 6010. Sometimes I find that I accidentally move files into the wrong folder. So the first thing that is needed is a way to prefix each file (email attachment) with the correct project number. If this is done even if it the email attachment files is moved by accident to another job directory I will know this as it will have a different name to its parent directory name. I will know which folder it originated from and then I can move it back to its original folder. The first part of this task is easy to do (I think) with the renaming function. However, the second part is to organise each of the files into categories based on their extension type.

So to explain, I may have a series of DWG files, PDF files, DOC files, ZIP files etc. So what I need is a script or button function that can first prefix the file name based on its parent folder name. For example, if the Parent folder's name is 6010 then each file contained under it will need to have that name prefixed to its name but even those that are contained in subfolders under the parent directory. Thus the script will have to be recursive. Once this is done I should end up with something like 6010_Name 1.DWG, 6010_Name 2.DWG ....6010_Name N.DWG and 6010_Name 1.PDF .. 6010_Name N.PDF etc. for each and every file extension type contained under the parent job folder.

The next task would be then to move each type of file (extension type) into its respective extension name folder under the parent folder. Thus the file structure in the end should look like this 6010/DWG/6010_Name 1.DWG, 6010_Name 2.DWG ....6010_Name; 6010_Name 1.PDF, 6010_Name 2.PDF ....6010_Name N.DWG N.PDF, 6010_Name 1.ZIP, 6010_Name 2.ZIP ....6010_Name N.ZIP, 6010_Name 1.DOC, 6010_Name 2.DOC ....6010_Name N.DOC and so on for each file extension type.

Now as I understand it the first part of the algorithm is just fairly simple and handled by the rename tool although it would need to drill down into sub-directories so as to change the names of each file which are contained in those sub-directories again recursion is needed. The last part is the hard part i.e. how can one move a whole lot of disparate files into folders that have been categories according to their extensions?

So I suppose the first thing to do is parse all the file extension types, then make sub-folders for each type i.e. DWG, PDF, ZIP, DOC ..etc. then somehow move all the files (even the ones in sub-folders) to the correct extension subfolder by parsing the file extension part of their of the file name. The last part would be to delete all the empty sub-folders so as to avoid confusion.

I suspect this is not to difficult to do in OPus but could someone help with such tasks. Ideally, each task needs to be in a simple script which could be stored as a button.

Kind regards, Mark

The built-in batch rename can rename using the name of the parent folder, but it's complicated by your need to handle files in sub-folders as well. I think this would require a rename script.

Hi Jon;

I am sure I am not the only one that needs to sort / categorise files into folders by file type or content. If this was a stock command in Directory Opus, I am sure this would be a great selling point for the program. There are some these type of software utilities for sale on the web but since they are often done by amateur programmers they tend to crash (too frequently for my liking) especially if sorting through many files. Thus I have not put my money on the table to purchase them but have tried them in demo mode. Having a File Juggler like capability in Directory Opus would save so much time for many Directory Opus users I suspect. I do not know if a script would have the "horsepower" if used on thousand of files but I maybe I could be proved wrong.

Kind regards, Mark