Solved Removing 1 character from names of files.

July 12, 2012 at 11:27:56
Specs: Windows XP
I am having a problem with filenaming. What I basically want to do is to have a batch file that removes the first letter of the name from a list of files in a directory. I looked at other questions people asked but I'm not sure how to enter the destination of where they are located or specify what kind of files are being renamed. So, if I have a directory on my desktop named: C:\Documents and Settings\Joey\Desktop\Monograms\123 , how would I be able to remove the 1st letter from all of the files in the folder "123"? And the files aren't text (.txt), they are a mixture of .DXF and .EPS files. Probably the longest filename would be about 8-12 characters long.
Here is the code that did not work...
------------------------------------------------------------------------------------------------------
@echo off
setlocal EnableDelayedExpansion
dir /b *txt > ~Files.txt

for /f %%a in (~Files.txt) do (
set Name=%%a
set Name=!Name:~1,20!
ren %%a !Name!
)
del ~Files.txt
endlocal
------------------------------------------------------------------------------------------------------
Please try to customize it so it works in my scenerio. Greatly appreciated.
- Joey

Please try to get an answer back ASAP!


See More: Removing 1 character from names of files.

Report •


#1
July 12, 2012 at 13:56:47
✔ Best Answer
@echo off & setlocal enabledelayedexpansion
set src=%homepath%\desktop\monograms\123
pushd !src!
for /f "tokens=*" %%i in (
'dir /b /a-d *.txt *.dxf *.eps'
) do (
set $=%%i
set $=!$:~1!
echo move "%%i" "!$!"
)
popd

Remove the echo to weaponize the script.

Tony


Report •

#2
July 13, 2012 at 09:55:22
What do you mean by "weaponize" by removing the echo?

Report •

#3
July 13, 2012 at 11:42:36
It will actually rename the files. Right now it just shows you what it would do but doesn't actually do it.

Tony


Report •

Related Solutions

#4
July 13, 2012 at 13:06:11
Wow, that is really amazing. Thank you very much!!!

You really helped me out ALOT!!!!!!!!!!!!!!!!!!!!

If it wasn't for you, I would not have been able to succeed!!!!!

Thankyou very VERY MUCH!!!!!!!!!


Report •

Ask Question