Accessing a remote mounted directory from Windows CMD.EXE

6

2

I have a remote directory that is shared and mounted to my localhost. I know the remote directory is mounted and shared correctly as I can read, write, execute the file during a normal mouse and click event.

Although, I do need to script something and would like to do this using the Windows cmd executable.

For example, I want to cd/ change directory into the the remote directory and rename the file.

How do I do so in a sample Windows script?

So far, the command line below isn't working for me. I might not be passing this properly in the first place.

C:\>cd \\myremotehost\MY_DIR

Error:

`\myremotehost\MY_DIR'

CMD does not support UNC paths as current directories

I want to script this and rename myfile to mynewnamefile.

jdamae

Posted 2011-06-10T02:10:45.523

Reputation: 277

The error message CMD gives you is very straightforward: "CMD does not support UNC paths". You need to map a drive to it so that CMD doesn't have to know that it's a UNC path. – jcrawfordor – 2011-06-10T02:18:55.690

Does it have to be with the UNC (\myremotehost\MY_DIR), or do you care if it is mapped (given a drive letter)? Do you want a workaround? – KCotreau – 2011-06-10T02:29:35.927

it doesn't matter for the directory name. I was able to mount using a letter. as long as i can make my way to the files. – jdamae – 2011-06-10T02:37:27.063

Duplicates this ServerFault question.

– JdeBP – 2011-06-10T10:28:54.807

Answers

7

You need to mount the network location as a network drive before you can use it from the command prompt. Like so:

net use x: \\myremotehost\MY_DIR
x:

Afterwards you should be able to perform whatever operations you want, using the X:\ in place of \myremotehost\MY_DIR. When you are done, you can disconnect the drive with

net use x: /delete

Fopedush

Posted 2011-06-10T02:10:45.523

Reputation: 1 723

You can also map the drive, x: in this case, from My Computer and it will work just the same in your script. – Garrett – 2011-06-10T02:23:09.627

@Fopedush- got the mount working now. Thank you. I can see the files using ls x: – jdamae – 2011-06-10T02:33:27.240

1

Your share is probably mounted as a drive letter. You would most likely want to do something like this:

ren X:\my file myfile

To script it, you could simply put the command into a .cmd file.

Kirk

Posted 2011-06-10T02:10:45.523

Reputation: 2 182

That assumes that he maps it. Ren does not work with UNC names. – KCotreau – 2011-06-10T02:17:24.213

It does assume he maps it. He did say it was mounted, which could mean a few things in Windowsland. – Kirk – 2011-06-10T02:21:53.340

@Kirk- thanks for your input. So far, I do have the mount now, thanks to Fopedush. Its "x:" . Although now I am trying to rename that file and getting The syntax of the command is incorrect. As for the obvious, I can see the files when i do ls x: Thanks! – jdamae – 2011-06-10T02:32:34.573

found it its ren x:\my file newfile. thanks guys! – jdamae – 2011-06-10T02:36:15.850

Edited my answer to reflect the correct syntax. – Kirk – 2011-06-10T02:42:46.833

1

Based on your comment, then what you want to do is this batch file:

x:

cd\directory

ren filename newfilename

The first command seems to be what you are missing.

Another workaround if you want to use the UNC is this:

xcopy \\server\directory\filename \\server\directory\newfilename

del \\server\directory\filename

The effect is the same.

KCotreau

Posted 2011-06-10T02:10:45.523

Reputation: 24 985

0

I recommend using 'net use' and map a drive letter and manually unmap it as it works on all versions of Windows.

However, it is good to know that pushd instead of cd will (depending on the version of Windows) map a drive letter for you automatically, but make sure to call popd to unmap the drive letter.

**pushd** \\server\directory\  
ren filename filenamenew  

rjt

Posted 2011-06-10T02:10:45.523

Reputation: 878