Page 1 of 1

How to move selected files to a specific folder using a Windows batch file?

Posted: 24 Jun 2021 18:02
by acousticsman
I organise my files every few months and by that time it becomes a behmouth of a mess.

I usually dump all files inside one folder then go through it and move to the approprate folder manually.

I am looking for a way to move the file(s) manually selected in the explorer to a sepcified folder.

This batch file code

Code: Select all

move c:\Sourcefoldernam\*.* e:\destinationFolder
will need to be amended so that it recognises the selected files.

I will then use Touch Portal to run the bat file(s) that will be set up with the folders I will move to. Every example in this regards is to find files by extention or file name etc, this won't work for me. I have searched for a way for the batch file to recognise the selected files but to no avail.

Re: How to move selected files to a specific folder using a Windows batch file?

Posted: 25 Jun 2021 06:56
by aGerman
The Batch process won't get the slightest idea of what files you selected in an explorer list view. You know, explorer.exe is one shell and cmd.exe is another one. You might be able to drag\drop selected files onto a Batch script in order to handle them like passed parameters. However, it's quite likely that it doesn't even get all of them if you selected too many. The reason is that dropped files come in including the entire path each. So, the command line grows and quickly becomes huge. The length of a command line is limited though.

Steffen

Re: How to move selected files to a specific folder using a Windows batch file?

Posted: 28 Jun 2021 14:23
by CJM
Create a shortcut to your batch file in the Send To folder, which is easily opened from the command line with:

Code: Select all

start shell:sendto
Then you can right-click on your selected files, click Send To; [your shortcut name]

The batch file will receive the list of files as arguments, which you can iterate through the old-style way:

Code: Select all

:loop
MOVE %1 TargetDir
SHIFT
IF NOT "%~1"=="" GOTO :Loop
or the this-century-newer command extension %* which is a list of all arguments:

Code: Select all

FOR %%F in (%*)do MOVE %%F TargetDir
The problem I run into with this though is depending on the length of your files' full path, you'll quickly exceed the maximum command length (see elsewhere, I don't have it handy) which limits the number of files that can be processed in a single operation. It's best to experiment by preceeding your MOVE command with ECHO so you can try it without affecting your files.