Batch Rename of Files in a Directory

     To achieve the task I created two .bat file. The first file will be the main Batch file that will loop through the the file in the directory. For every file that the process will see, it will execute the second batch file. The second batch file will be called by the main batch file for the function of substring and will rename the file.

Main Batch File. I renamed this file as BatchRen.bat
========================================
@echo off
for %%x in (%1) do (
    call ren2 %%x %2 %3
    )

========================================

Second Batch File. I renamed this file as Ren2.bat
========================================
@echo off
set x=%1
call set substring=%%x:~%2%%
@echo on
ren %x% %substring%

========================================

Executing the batch file. In the command prompt type in
C:/ BatchRen *.csv 6 *****.scv

This is the original files







Execute the command













After the execution the files will be renamed. in this instance we removed the first 5 characters in all csv files.







Microsoft Windows 7 Home Premium Upgrade

Comments

Popular Posts