I have a bunch of .xlsx files that are generated every month. I would like to be able to batch move the files to folders which have basically the same name.
Example: 123456 Action.xlsx, 123456 RC.xlsx, 123456 PF.xlsx would be the files. The folder would be 123456 Random Center.
Is there a way to move those files to that folder using a batch command or something else through the command prompt?
Here is the the code I have been trying to use/modify.
@echo off
pushd "C:\New folder"
rem Process all files in this folder separating the names at " "
for /F "tokens=1* delims=-" %%a in ('dir /B .xlsx') do (
rem At this point %%a have the name before the " " and %%b the rest after " "
rem Create the folder, if not exists
if not exist "%%a" md "%%a"
rem Move the file there
move "%%a-%%b" "%%a"
)
popd
That creates a folder named %%a but puts nothing in it. I'm stuck and need some help.