rd/s with symlinks and junctions

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
Mar 23, 2009
7
0
#1
If I create a symlink (or a junction) to a directory and then do a "rd/s" of that directory, TCC deletes all of the files in the linked directory.

The rd command in the (Vista) cmd shell merely deletes the symlink, leaving the files in the target directory alone.

Is there any way to tell TCC to behave the same way?

TIA,
Kb
 
May 26, 2008
481
3
#2
Good suggestion.

You might be able to set up an RD alias that checks to see if the directory is a junction (perhaps using the @JUNCTION function?). If so it would call MKLNK /D, otherwise it could run the regular RD command.


Also Rex, I noticed that MKLINK /? does not show the "/Q" switch but the help file does.
 
#3
On Tue, Mar 24, 2009 at 4:12 AM, kb1001 <> wrote:

> If I create a symlink (or a junction) to a directory and then do a "rd/s" of that directory, TCC deletes all of the files in the linked directory.
>
> The rd command in the (Vista) cmd shell merely deletes the symlink, leaving the files in the target directory alone.

TCC 10.00.61 Windows XP [Version 5.1.2600]
TCC Build 61 Windows XP Build 2600 Service Pack 3

I'm using XP instead of Vista, but my testing does not show what you say.

The RD command in CMD and TCC both just remove the junction.

The RD /S command in CMD and TCC both delete the files.


--
Jim Cook
2009 Saturdays: 4/4, 6/6, 8/8, 10/10, 12/12 and 5/9, 9/5, 7/11, 11/7.
Next year they're Sunday.
 
#4
Rod Savard wrote:
| You might be able to set up an RD alias that checks to see if the
| directory is a junction (perhaps using the @JUNCTION function?). If
| so it would call MKLNK /D, otherwise it could run the regular RD
| command.

Use %@wattrib[dir,L] as your test, e.g., UNTESTED:

alias RDS=`iff %@wattrib[%1,L] eq 1 then %+ mklnk /d %1 %+ else *rd/s %1 %+
endiff`

--
HTH, Steve
 
Mar 23, 2009
7
0
#5
Rod Savard wrote:
Use %@wattrib[dir,L] as your test, e.g., UNTESTED:

alias RDS=`iff %@wattrib[%1,L] eq 1 then %+ mklnk /d %1 %+ else *rd/s %1 %+
endiff`

--
HTH, Steve
I have just been doing

alias rd=cmd /c rd

which works fine. But, I'm worried about someone else who might be running TCC without my alias.

Kb
 
Mar 23, 2009
7
0
#6
Jim,

Symlinks are new in Vista, and the RD command works differently on Vista than XP. If you try it on Vista you'll see what I mean. I guess someone at Microsoft must have reworked it to avoid the "problem" (at least as far as my usage is concerned.)

Kb
 
Mar 23, 2009
7
0
#7
Steve,

BTW, the reason I can't use the alias you suggest is that the RD command is recursive. If I do an rd/s on a root that contains a nested linked directory, I don't want it to delete the files.

Kb
 

rconn

Administrator
Staff member
May 14, 2008
10,101
85
#8
kb1001 wrote:

> If I create a symlink (or a junction) to a directory and then do a "rd/s" of that directory, TCC deletes all of the files in the linked directory.
>
> The rd command in the (Vista) cmd shell merely deletes the symlink, leaving the files in the target directory alone.
>
> Is there any way to tell TCC to behave the same way?
Well, yes, you could leave off the /S.

(I'm puzzled why you would *want* to do an RD /S of a symlink or junction.)

Rex Conn
JP Software
 
Mar 23, 2009
7
0
#9
In my case, what I want to do is create a (real) directory that contains symlinks to a series of other directories that are scattered about on a disk (or disks), to provide a logical "view" of files different from the physical organization [actually it's more complicated than that because the "view" can be deeply nested with real directories, real files, symlink'd files and symlink'd directories at any level].

So to clean the view, I must do an "rd/s" and I definitely don't want to delete any files from the symlink'd directories.

HTH,
Kb
 
#10
kb1001 wrote:
| In my case, what I want to do is create a (real) directory that
| contains symlinks to a series of other directories that are scattered
| about on a disk (or disks), to provide a logical "view" of files
| different from the physical organization [actually it's more
| complicated than that because the "view" can be deeply nested with
| real directories, real files, symlink'd files and symlink'd
| directories at any level].
|
| So to clean the view, I must do an "rd/s" and I definitely don't want
| to delete any files from the symlink'd directories.

I think you could use DEL /S /NJ /X - but I haven't tested it.
--
HTH, Steve