rename a file in a batch script

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
Squashman
Expert
Posts: 4470
Joined: 23 Dec 2011 13:59

Re: rename a file in a batch script

#16 Post by Squashman » 08 Jul 2014 07:01

Sure looks like it works fine to me.

Code: Select all

C:\BatchFiles\rename5>dir /b
012345.txt
012346.txt
rename5.bat

C:\BatchFiles\rename5>rename5.bat
Press any key to continue . . .

C:\BatchFiles\rename5>dir /b
12345.txt
12346.txt
rename5.bat

C:\BatchFiles\rename5>

helene
Posts: 9
Joined: 07 Jul 2014 02:29

new script

#17 Post by helene » 08 Jul 2014 11:44

i want a script that will rename a series of files name like 012345.txt 012346.txt 0123457.txt and so on.they are located in the c drive in a folder name code .
i receive this file from a server and i hav to send them to another server but the application suport only 5 characters as a name.
i already wrote 3 differents scripts that save the files in another folder and the second script rename them but when renaming instead of deleting the 1st number it replace it by space which is considering as a character and the third script send them to the application. so i want the second script that will delete directly the 1st number and not replacing it.

Samir
Posts: 384
Joined: 16 Jul 2013 12:00
Location: HSV
Contact:

Re: new script

#18 Post by Samir » 08 Jul 2014 12:22

Post your rename scripts and some examples.

Squashman
Expert
Posts: 4470
Joined: 23 Dec 2011 13:59

Re: rename a file in a batch script

#19 Post by Squashman » 08 Jul 2014 12:25

I have merged your topics together because it is a continuation of an existing issue you have.

einstein1969
Expert
Posts: 941
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: rename a file in a batch script

#20 Post by einstein1969 » 08 Jul 2014 12:44

Hi Helene,

are the extensions of your files .TXT? if yes...

try this script and check if return the right name for the file to send at the application.

Code: Select all

@echo off
setlocal EnableDelayedExpansion

for %%G in (*.txt*) do  (set "name=%%G" & echo '!name:~-9!')


The result is between ' ' for check SPACE at beginning-end.

einstein1969

Post Reply