Vista: mklink command results in invalid directory name?

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
Hey guys, wonder if anyone has some insight on this one. I was playing around with mklink in Vista today, with an eye toward using it to free up some space on my C: drive, similar to what you might do in Linux with a symlink and /usr, for example.

Following some blog posts I read, I opened a command prompt, normal user privs, copied a small directory to my D drive, then renamed the source to name_old. I then did the following:

mklink /J name d:\where_name_is_now

After that I could see "<JUNCTION> name [D:\where_name_is_now]" in the directory listing for the original location. So far so good, and very similar to what I expected from doing it on linux.

I then tried to cd to the linked directory through the link...

C:\Parent>cd name
The directory name is invalid
C:\Parent>

Eh? What's that? I did some quick searching and saw this error referenced in lots of other contexts, but didn't see anything related to making a symlink. I did see reference to elevation, and belatedly considered that maybe I should have been admin when I did this. So I opened en elevated command window and tried to access the dir. Same result. I then went to the D: drive and tried to access the dir directly. Same result.

So, not sure what to think at this point. I can't access the directory, or delete it. Seems like I have a farked file system? Any ideas?
 

ViRGE

Elite Member, Moderator Emeritus
Oct 9, 1999
31,516
167
106
Don't use Junctions. Use a symbolic link. Junctions are crazy.

MKLINK [[/D] | [/COLOR] | [/J]] Link Target

/D Creates a directory symbolic link. Default is a file
symbolic link.
/H Creates a hard link instead of a symbolic link.
/J Creates a Directory Junction.
Link specifies the new symbolic link name.
Target specifies the path (relative or absolute) that the new link
refers to.

C:\test>mklink /d bar c:\windows
symbolic link created for bar <<===>> c:\windows

Edit: Also, http://en.wikipedia.org/wiki/NTFS_junction_point

Never delete a junction point using Explorer, a del /s command, or other file system utilities that walk recursively into directory trees. These utilities will affect the target directory and all subdirectories. Instead, use the utilities described below to delete junction points.
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
Cool, thanks for the tip. I only used junction because the blog post I was reading said that /D didn't work right for directories. Oh well.

Edit: that worked great. Thanks again. Very slick. So now the big question: has anyone used a symlink to move Program Files to another drive?