1.

Solve : Help to move files based on filename - Batch Script?

Answer»

Hi Experts,

Need your urgent help to create my batch script. I am pretty NEW to batch scripting, so need your help to solve my problem.

I have .xls files in my directory with names ending with *MONYY.xls (e.g. NL_PO_Accrual_Aug14.xls)

Now, I want a batch script to check if any folder exists in same directory named "Aug14". If yes then just move all the files ending with Aug14.xls to "Aug14" else create folder "Aug14" and then move the files.

I can schedule this batch file daily to check the newly created files in the directory and move them to their respective month folders.

Please help!! (let me KNOW if you need more details)

Regards,
SimranTest this on a folder of sample files:

Code: [Select]echo off
setlocal enabledelayedexpansion
cd /d "c:\folder\xlsfiles"
for %%a in (*.xls) do (
   set "monYY=%%~na"
   set "monYY=!monYY:~-5!"
   md "!monYY!" 2>nul
   if EXIST "%%a" move "*!monYY!.xls" "!monYY!"
)
pause
Great...thanks a lot...it worked.

One more thing...just a small one

the batch file would not be placed at the directory. So, i need to do this function at some other location.

Where should I enter the path as current code you provided checks XLS files in same folder.

Please advise!!

-SimranI added one line to the code above. 
Thanks Foxidrive

You solved my problem in seconds...I do appreciateHi All,

One more small issue...i m not able to give proper path for the directories/lists

I am giving value as
cd /d "\\server123\WEB\Acc_Report\Test\rcv"

But when I run the code it says "

'\\server123\WEB\Acc_Report\Test\rcv'
CMD does not support UNC paths as current directories.

Please help!!!

THanks,
SimIt worked guys....I used pushd command instead of cd /d

Now its working

  If you just WANTED a directory list you COULD just use the DIR command with the UNC path.
Code: [Select]C:\>dir  \\server\share\folder



Discussion

No Comment Found