How to delete a Windows directory without the following connection points?

I have a Perl script that should remove a directory with all its contents. Sometimes this directory contains a junction point in another directory. If I rmtree() naively, calling rmtree() will also delete all the files inside the connection destination folder. I am looking for a way not to do this, but instead just delete the connection.

Non Perl solutions would also be appreciated.

+6
perl winapi junction
source share
3 answers

I just typed the “junction point” on Google and found a way to http://en.wikipedia.org/wiki/NTFS_junction_point

Command line (cmd.exe)

  • The command line in Windows 2000 or later recognizes junction points by displaying directory lists instead (use the directory with / A or / AL).
  • Any commands that are usually files inside a regular directory will act the same here. Thus, the del myjunction command should not be used - it will simply delete all files in the target directory.
  • The rmdir commands also work fine with transitions, with a caveat that moves will not allow the transition to go to another volume (unlike Windows Explorer, as mentioned above.)
  • The rmdir command is safe in that it only deletes the junction, not the target files. When strolling through a directory with a command line interface, files can be deleted, but unlike explorer, directories can also be deleted (using rmdir / s dirname for Example.)
  • Using the linkd command with the / d switch is a safe way to remove the connection point.

From what I see, you can, for example, use dir and grep output for <JUNCTION> or use Windows rmdir . I think you can use any of them with Perl via system .

+6
source share

To find out where the reprocessing points are (or “join points” if you want):

 dir /a:l /b > myjunctions.txt 

Will show all reprocessing points in the current directory. You can add / s, but be careful that the reprocessing points inside the reprocessing points will also be specified.

Suppose myjunctions.txt contains the string x: \ subdir \ foo. To remove it, you release

 fsutil reparsepoint "x:\subdir\foo" 

And howl! Your connection point is missing, and the source directory is not touched!

+4
source share

The FastCopy utility does this: http://ipmsg.org/tools/fastcopy.html.en

I use this program to copy or delete folders that may contain transitions as subfolders so that the connection targets remain untouched. Connection points are correctly copied when copying, even if the destination drive is different.

Windows Explorer, at least in Windows 7 Ultimate, works the same as when uninstalling - connection targets remain intact.

But copying folders containing transitions as subfolders in Explorer still does not work properly - in fact, it does what I can’t fully describe: the transition folders seem to be copied like regular folders, but their contents are empty.

+3
source share

All Articles