I have a batch file designed to copy files into folders alphabetically, like so:
if exist "The A*.*" dopusrt.exe /cmd copy MOVE QUEUE=QueueName,quiet WHENEXISTS=replace "The A*.*" to Folder_A
if exist "A*.*" dopusrt.exe /cmd copy MOVE QUEUE=QueueName,quiet WHENEXISTS=replace "A*.*" to Folder_A
if exist "The B*.*" dopusrt.exe /cmd copy MOVE QUEUE=QueueName,quiet WHENEXISTS=replace "The B*.*" to Folder_B
if exist "B*.*" dopusrt.exe /cmd copy MOVE QUEUE=QueueName,quiet WHENEXISTS=replace "B*.*" to Folder_B
and so on down to "Z."
An "A" file whose name started with "The," like "The Archies.txt," would thus go into the "A" folder along with "ABBA.txt." Likewise, "The Beatles.txt" and "Badfinger.txt" would both go into the "B" folder, and so on. The problem is when I get to the letter "T." If I have a "T" file name starting with "The," like "The Temptations.txt," it gets queued twice -- once by each of the two lines handling the "T" files. Is there any way to make these commands wait to execute until the one before it has finished? It seems to me that would settle it. Thank you.
It looks like what you're doing is designed to run from an Opus button or hotkey, and presumably only uses dopusrt.exe so that it can use the MS-DOS "if exist" conditional. If so, using a script button or script command is a better way to do conditional logic.
However, looking at the commands you're running, you probably do not need conditional logic at all. Is the aim to move everything in the folder, whether selected or not, that matches the patterns in the "if exist" statements?
Let us know what you're trying to do overall and we can show the best way to achieve it.
Yes, the aim is to move everything in the folder (every week we get a few hundred documents we need sorted by file name), a specific folder which is used only as a temporary depository for these particular files. And I actually designed it more as a batch file (vs. a button), given my limited scripting skills.
Here's a simple command (just covering A, B, C; repeat as needed for the rest of the letters):
Copy MOVE "D:\Input Folder\(The |)A*" TO "E:\Output Folder" CREATEFOLDER "Folder_A"
Copy MOVE "D:\Input Folder\(The |)B*" TO "E:\Output Folder" CREATEFOLDER "Folder_B"
Copy MOVE "D:\Input Folder\(The |)C*" TO "E:\Output Folder" CREATEFOLDER "Folder_C"
That can be put on an Opus button or hotkey and then run from any folder. It will move everything out of D:\Input Folder into E:\Output Folder\Folder_X where X is the first letter (skipping the word "The ").
Any files or folders which don't start with a letter, and which are directly below D:\Input Folder, will be left where they are. (You can adjust the patterns as needed to cover them, or move * into an "Other" folder or similar, as desired.)
This could also be done with a script that loops through the letters, rather than the same command listed out repeated 26 times, but I figured this kept things simple and stayed close to the original plan.
Shout if anything is unclear.
I left WHENEXISTS=replace out for now, just so that if the command doesn't work as expected, it will warn you before overwriting anything. Please test that it works how you want it to, on some dummy files and folders, before adding that back in, just in case.
You probably won't need the QUEUE=QueueName,quiet part at all, since each command will wait for the other automatically. (That was only needed before because dopusrt.exe doesn't wait, but we're not using that now.) You should only need to worry about queues now if you're worried about other copy/move commands that you run at the same time running in parallel. (Or if you want to avoid other copy commands from automatically queueing behind these ones if they are to the same destination.)
Thank you. But doesn't this approach also have the effect of shunting files with names like "The Unicorns.txt" or "The Zebras.txt" into the "T" folder (in other words files whose names begin with "the" and a first letter later in the alphabet than "T")?
I suppose I could move the "T" line to the end of the list, so it's executed last, but I also need to account for file names beginning with "A " and "An ".
It does skip the word "The" when the second word begins with "A" through "S." But when the script gets to the letter "T" it moves all the rest of the files starting with "The" into the "T" folder. (I'm guessing because the word "The" starts with "T.")
If there are other words, a script may be a better approach, since then it can use more advanced logic.
What are the full list of words, and are there any other requirements?
It's best to know all the requirements up-front so we can design something that will do everything you need, otherwise we might pick a solution that is easier but won't be able to do something we don't know about yet.
The only other prefix words that need special handling are "A" and "An." I limited my example above to "The" only because I was trying to keep it simple, thinking if I was just pointed in the right direction I could figure out the rest as I became more familiar with Directory Opus syntax and pattern matching.
Right now I'm leaning putting the "A" and "T" lines at the end and using the "~" operator to exclude files I don't want moved right away.