Renaming a file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2015 12:48 AM - edited 03-01-2019 09:18 AM
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.
- Labels:
-
Cisco Workload Automation
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2015 04:12 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2015 06:57 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2015 08:10 AM
Can you try with
<source file.502>="abcde.txt"
<prefix.503>="xyz_"
I suspect the '*' is causing the issue
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2015 02:10 AM
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"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2015 08:38 AM
Thanks Dinesh, it is working now.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2015 12:28 PM
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>
