rename multiple files with script

190 views Asked by At

I found this script on here and modified it. It works only for 1 file at a time not multiple files. How can I get this script to rename multiple files in the directory specified?

@echo off
setlocal enabledelayedexpansion
set X=64
set Y=4
set FOLDER_PATH=c:\temp\renamefiles\files
pushd %FOLDER_PATH%
for %%f in (*) do if %%f neq %~nx0 (
  set "filename=%%~nf"
  set "filename=!filename:~%X%,-%Y%!"
  ren "%%f" "!filename!%%~xf"
)
popd    
2

There are 2 answers

0
Tom Lenc On

I don't really know what you mean, but this is working for me:

ren "path\to\your\folder\*.*" "foo.*"

If you execute this command, every file, no matter if there are .txt, .png, .foo, .bar,.. files.

Every file in that folder will get renamed to "foo". But if there are for example four .png files, there will be only one .png file falled foo.png, because the others can't rename when there is other files with the exactly same name already there.

1
MrP On

I don't really understand these but I think you're renaming every files with the same name and that is illegal (for example you can't have a file.txt on a directory that already has file.txt) But I am not sure if that is really the case since I don't understand the given code.