Computing.Net > Forums > Windows NT > rename part of a file name

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

rename part of a file name

Reply to Message Icon

Name: Lee andrews
Date: September 17, 2002 at 03:02:47 Pacific
OS: win nt
CPU/Ram: p4 256m
Comment:

I need to replace part of a file name using a command line utility.

I have a directory full of files all prefixed with a name that I want to change, unfortunately the name i want to change to is longer than the original name so

rename oldname*.txt longname*.txt
changes
oldname@file.txt to longnamefile.txt
note the missing @ from the name e.g. it should gave been longname@file.txt

any ideas?



Sponsored Link
Ads by Google

Response Number 1
Name: Jimbo
Date: September 17, 2002 at 04:02:12 Pacific
Reply:

The resource kits have good tools for this kinda thing..


0

Response Number 2
Name: Carl
Date: September 17, 2002 at 05:16:48 Pacific
Reply:

Moin Lee,
this way it will work:
ren DriveLetter:\path\???@file.txt verylong@file.txt
where you must type exactly as many questionmarks as the old filenames' identical part has got spells.
mfg, Carl.


0

Response Number 3
Name: Lee andrews
Date: September 17, 2002 at 05:34:18 Pacific
Reply:

Thanks guys....

I needed to do this with an environment variable.... I came across this on a scripting site and it works...
for %%f in (*.txt) do call :RENAME %%f
:RENAME
echo Called with %1
for /f "eol=; tokens=1* delims=@" %%I in ("%1") do rename %1 %env_variable%@%%J

So job done thanks.

Carl thanks - I would have needed to know how many chr in the original file - is there a length function in batch files so I could work out how many ???? to use? I'm doing this on multiple machines with multiple users. Basically Im trying to migrate the users cookies in a login script without asking the user to do anything.



0

Response Number 4
Name: Renaissance Man
Date: September 17, 2002 at 05:38:41 Pacific
Reply:

The "problem" with the original code is that it does exactly what you asked: @ is part of oldname and you did not include it in longname.

Instead of ren DriveLetter:\path\???@file.txt verylong@file.txt

Why not ren DriveLetter:\path\*@file.txt verylong@file.txt

That way it will change any size oldname file withoput having to count "?".



0

Response Number 5
Name: Lee andrews
Date: September 17, 2002 at 05:46:50 Pacific
Reply:

Hi

"Why not ren DriveLetter:\path\*@file.txt verylong@file.txt"

I'm trying to rename every instance of oldname@something.txt not one instance so I need a wildcard in both parts of the command.

your command would rename every file to verylong@file.txt , well it would try to but fail after the first instance.

what i have is lots of files:
oldname@bt.com.txt
oldname@microsoft.com.txt
oldname@citrix.com.txt

and I want to rename them all to
newname@bt.com.txt
newname@microsoft.com.txt
newname@citrix.com.txt

Thanks for the help guys... but I have a solution in my previous post now using a for command.


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Windows NT Forum Home


Sponsored links

Ads by Google


Results for: rename part of a file name

apend info to the start of a file www.computing.net/answers/windows-nt/apend-info-to-the-start-of-a-file/23186.html

Close a file on a busy share? www.computing.net/answers/windows-nt/close-a-file-on-a-busy-share/3270.html

Web - Equivalent file names in IIS. www.computing.net/answers/windows-nt/web-equivalent-file-names-in-iis/6669.html