cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
10301
Views
0
Helpful
6
Replies

Renaming a file

5vrajasekaran
Level 1
Level 1

Hi,

I need to rename a file name with four character prefix followed by the original file name.

eg) abcde.txt to xyz_abcde.txt.

 

I tried with the normal renaming command ren path\abcde.txt xyz_*.txt.

Output I got was xyz_e.txt, the first four character of the orginal file name was replaced by the prefix, this is what I was not expecting.

Could someone help me to solve this issue.

6 Replies 6

Seems like a batch script question. The rename command is behaving as expected.

Have you tried using Tidal variables to hold the values abcde.txt and xyz_ and use them in yoru jobs ?

For example,

ren path\<fromfilename> <prefix><fromfilename>

where fromfilename(="abcde.txt") and prefix(="xyz") are Tidal variables

Hi Dinesh,

Triedby the way you suggested

/c ren \\path\<source file.502> <prefix.503>_<source file.502>

 <source file.502>=*.txt

<prefix.503>=xyz

But still the renaming is not as expected.

Can you try with

<source file.502>="abcde.txt"

<prefix.503>="xyz_"

I suspect the '*' is causing the issue

encountered the issue with the following command inside  a batch file

 

for %%f in (File name to be renamed) do copy "%%f" "path\prefix name%%f"

Thanks Dinesh, it is working now.

or maybe a batch file something like

echo off for %%i in ("abcd*.txt") do (set fname=%%i) & call :rename goto :eof :rename ::Cuts off 1st 4 characters of fname, then appends prefix ren "%fname%" "xyz%fname:~4%" goto :eof

e.g.

R:\temp>dir abc*.txt
 Volume in drive R is dot_home
 Volume Serial Number is 009A-9A03

 Directory of R:\temp

11/02/2015  03:12 PM                 3 abcd2.txt
11/02/2015  03:12 PM                 1 abcd3.txt
11/02/2015  03:11 PM                 3 abcd1.txt
               3 File(s)              7 bytes
               0 Dir(s)  29,211,370,536,960 bytes free

R:\temp>rename_file.bat
R:\temp>echo off
R:\temp>dir xyz*
 Volume in drive R is dot_home
 Volume Serial Number is 009A-9A03

 Directory of R:\temp

11/02/2015  03:12 PM                 1 xyz3.txt
11/02/2015  03:12 PM                 3 xyz2.txt
11/02/2015  03:11 PM                 3 xyz1.txt
               3 File(s)              7 bytes
               0 Dir(s)  29,200,234,905,600 bytes free

R:\temp>

Review Cisco Networking for a $25 gift card