Link to home
Start Free TrialLog in
Avatar of dmanisit
dmanisit

asked on

Script to rename many files

Hi, I have about 2000 image files that are structured like this: Q-Images0D264A61-9F97-4E6A-8EC8-500156287BEC0001.TIF I need a script that will drop the Q-images and leave everything else. Can anyone help?
Avatar of knightEknight
knightEknight
Flag of United States of America image

@echo off
setlocal enabledelayedexpansion

CD/d "C:\myfolder"

for %%F in (Q-Images*.TIF) do (
  set _FN=%%F
  ren  "!_FN!"  "!_FN:~8!"
)
alternatively, you can replace this line:

   ren  "!_FN!"  "!_FN:~8!"

with this one:

   echo ren "!_FN!"  "!_FN:Q-Images=!"
oops, but remove the "echo" from the second one.
ASKER CERTIFIED SOLUTION
Avatar of knightEknight
knightEknight
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Are the filenames a static length? if they are this should do it.
Set oFS = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFS.GetFolder("C:\PATH")
For Each oFile In oFolder.Files
	WScript.Echo oFile.name
	WScript.Echo oFile.path
	If Left(Lcase(oFile.name),8) = "q-images" Then
		oFS.CopyFile oFile.path, "C:\PATH\" & Right(oFile.name,Len(oFile.name) - 7)
	End If
Next

Open in new window

actually that will work if they are not static it is going to look at the length of the file name and take 7 off of that which should remove the Q-Images portion of every file.
Avatar of dmanisit
dmanisit

ASKER

thank you