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

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
acousticsman
Posts: 1
Joined: 24 Jun 2021 18:01

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

#1 Post by acousticsman » 24 Jun 2021 18:02

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.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

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

#2 Post by aGerman » 25 Jun 2021 06:56

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

CJM
Posts: 24
Joined: 25 Oct 2019 20:34
Location: Baltimore, MD USA

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

#3 Post by CJM » 28 Jun 2021 14:23

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.

Post Reply