Solved Command to move folders based on the entries in a text file

March 14, 2012 at 14:52:53
Specs: Windows
I have to move 100s of folders to several different folders and I am looking for a command to move them as described in a text file, where the file tells the OS which files to move. I've used a command to create folders based on what's entered in a text file, which is below for reference.

for /f "usebackq delims=" %A in ("C:\textfile.txt" ) do md "C:\thisfolder\%A"

Any help would be much appreciated.


See More: Command to move folders based on the entries in a text file

Report •

✔ Best Answer
March 15, 2012 at 20:19:28
"However, where in the command you provided do I tell DOS the destination of the move?"

That is just it! You want to move all these folders to several different other folders based on some criteria (I am guessing personal judgement). Therefore, you can't hard-code the destination into the command. The code I provided uses "%j" for the destination, which has to be read from your data file, which means you have to include that information. That is a real %@$#*& of a task to do in a plain text editor, but very easy to do in a spreadsheet. Spend 15 more seconds to add another column with the text "MOVE /Y" in every cell and you have the complete set of MOVE commands for everything! Then export your spreadsheet to a space delimited text file and change its extension to ".BAT" and you have an "easier, faster, safer and self documenting" method to move your folders.



#1
March 14, 2012 at 23:17:22
I can only guess what the content of your text file might be, or how you had thought about creating it, but I think something like the following might work for you:

FOR /F "usebackq tokens=1,2 delims=," %i in (C:\movefile.txt) do move %i %j

IMHO for the amount of time you would have invested creating this datafile, and debugging the command(s) to interpret it, it would be easier, faster, safer and self documenting to assemble the commands you want to execute in an Excel worksheet and export them to a batch file. In the event anything went wrong, you could use the worksheet to traceback what happened and reverse the damage.


Report •

#2
March 15, 2012 at 07:35:11
I am on OS X but will be doing the move on a Windows machine, so I can just copy and paste the folder names into the text file on the Mac, which makes it very easy. I have that part figured out.

So the text file would look like this:
Folder A
Folder B
etc, etc...

However, where in the command you provided do I tell DOS the destination of the move? Thanks.


Report •

#3
March 15, 2012 at 14:03:48
A function that copied the files would also work.

Report •

Related Solutions

#4
March 15, 2012 at 20:19:28
✔ Best Answer
"However, where in the command you provided do I tell DOS the destination of the move?"

That is just it! You want to move all these folders to several different other folders based on some criteria (I am guessing personal judgement). Therefore, you can't hard-code the destination into the command. The code I provided uses "%j" for the destination, which has to be read from your data file, which means you have to include that information. That is a real %@$#*& of a task to do in a plain text editor, but very easy to do in a spreadsheet. Spend 15 more seconds to add another column with the text "MOVE /Y" in every cell and you have the complete set of MOVE commands for everything! Then export your spreadsheet to a space delimited text file and change its extension to ".BAT" and you have an "easier, faster, safer and self documenting" method to move your folders.


Report •

#5
March 16, 2012 at 06:00:23
Ok, that makes sense, I see what you mean about the spreadsheet part.

So if I make the .BAT, do I put its file name in the command instead of the .txt?

And when I have the text for the .BAT, would it look like this:

"C:/Folder_A" MOVE /Y "C:/New Location/"

I really appreciate your help!


Report •

#6
March 16, 2012 at 06:52:41
Let me correct myself. Would it read:

MOVE /Y "C:\Folder A" "C:\New Location"

I use quotes/spaces on purpose because the folder names have spaces in them. And do I close each folder path with any special character so it knows I am moving the folder and not a file within the folder?


Report •

#7
March 16, 2012 at 11:17:11
I just answered my own question with a little research on the MOVE function.

I made a BAT and tried to move a folder and it worked. I just did my big move, only a small few hiccups, but I have the end result I wanted. Again, THANKS A LOT! Lots of time saved.


Report •

Ask Question