15

In the command prompt, I need a way up rename a file on a remote server. Conceptually, this is what I am looking for:

ren \\servername\folder\file.txt \\servername\folder\file2.txt

Aside from using PSTools, is there a way to do this locally from the C: drive? I think I can also map a network folder to a drive letter and do it that way, but this batch file I am using needs to be usable by everyone and can't require the user to map a drive. If that is the only way then I guess I'll have to go with it.

2 Answers 2

26

Do not use a full path for the second argument. Only the first argument requires a full path. Windows assumes since you are renaming, the file will remain in the same folder as previously specified. It mentions this in the command help at the bottom:

C:\Users\John>ren /?
Renames a file or files.

RENAME [drive:][path]filename1 filename2.
REN [drive:][path]filename1 filename2.

Note that you cannot specify a new drive or path for your destination file.

e.g.:

ren \\servername\folder\file.txt file2.txt

Alternatively you can map a drive letter to the UNC share and then issue a command such as:

ren Z:\file.txt file2.txt
0
0

As an alternative to the ren command, you can use the DOS move command to achieve the same result, and full paths are accepted for both arguments:

move \\server\share\path\to\file.txt \\server\share\path\to\file.csv

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .