Remove first character of a file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Abuh
Posts: 3
Joined: 14 Apr 2010 03:16

Remove first character of a file

#1 Post by Abuh » 14 Apr 2010 03:23

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

!k
Expert
Posts: 378
Joined: 17 Oct 2009 08:30
Location: Russia

Re: Remove first character of a file

#2 Post by !k » 14 Apr 2010 08:41

Numbers are always 6? More examples, plz

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

Re: Remove first character of a file

#3 Post by avery_larry » 14 Apr 2010 13:12

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

Abuh
Posts: 3
Joined: 14 Apr 2010 03:16

Re: Remove first character of a file

#4 Post by Abuh » 20 Apr 2010 09:32

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.

!k
Expert
Posts: 378
Joined: 17 Oct 2009 08:30
Location: Russia

Re: Remove first character of a file

#5 Post by !k » 21 Apr 2010 03:08

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

Abuh
Posts: 3
Joined: 14 Apr 2010 03:16

Re: Remove first character of a file

#6 Post by Abuh » 24 Apr 2010 08:23

It works

Thank You

Rastamind
Posts: 2
Joined: 19 Mar 2009 19:17

Re: Remove first character of a file

#7 Post by Rastamind » 25 Apr 2010 12:59

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"
)

Post Reply