Page 1 of 1

Remove first character of a file

Posted: 14 Apr 2010 03:23
by Abuh
Hello,

I'm asking your help because i need to crete a batch which rename files like A123456B.123 and the result like 123456ZZ.TXT

Do you have a idea?

Thanks in advance

Re: Remove first character of a file

Posted: 14 Apr 2010 08:41
by !k
Numbers are always 6? More examples, plz

Re: Remove first character of a file

Posted: 14 Apr 2010 13:12
by avery_larry
I'm not completely sure what you want but . . .

Code: Select all

for %%a in (*) do call :process "%a"
goto :eof
:process
set "fname=%~1"
ren "%fname%" "%fname:~1%"
goto :eof

Re: Remove first character of a file

Posted: 20 Apr 2010 09:32
by Abuh
For !k
Yes, the files always start with the same character.
Exemple: D100318A.MLK ; D090814A.MLK ...
I want to rename them like: 10031801.TXT ; 09081401.TXT ...
Is it possible?

For avery_larry
I don't understand what you wrote but i can try.

Re: Remove first character of a file

Posted: 21 Apr 2010 03:08
by !k

Code: Select all

@echo off
setlocal enableextensions
for %%a in (D*.MLK) do call :process "%%a"
exit /b

:process
set "fname=%~1"
set "n=0"
:loop
set /a n+=1
set "e=0%n%"
set "e=%e:~-2%"
set "nname=%fname:~1,6%%e%.TXT"
if not exist "%nname%" (ren "%fname%" "%nname%") else goto :loop
goto :eof

Re: Remove first character of a file

Posted: 24 Apr 2010 08:23
by Abuh
It works

Thank You

Re: Remove first character of a file

Posted: 25 Apr 2010 12:59
by Rastamind
Abuh wrote:D100318A.MLK ; D090814A.MLK ...
I want to rename them like: 10031801.TXT ; 09081401.TXT ...

Code: Select all

@echo off
setlocal enabledelayedexpansion
for %%a in (*.mlk) do (
set "filename=%%~na"
ren "%%a" "!filename:~1,-1!01.txt"
)