Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

<JUNCTION>; how to recognize

by fatkatie (Initiate)
on Oct 10, 2018 at 18:38 UTC ( #1223819=perlquestion: print w/replies, xml ) Need Help??
fatkatie has asked for the wisdom of the Perl Monks concerning the following question:

low hours pilot here

I want to recognize a uSWin directory type '<JUNCTION>'

If I do a command window 'dir' this entry is not shown.

If I do a command window 'dir /a:d' the entry is shown as: 07/14/2009  12:08 AM    <JUNCTION>     Documents and Settings [C:\Users]

If I do a perl opendir and iterate, the entry, array file name, is shown as:  Documents and Settings

Using file tests -d and -l has not helped me recognize the junction. Is there a way to do so?

env:
This is perl 5, version 18, subversion 4 (v5.18.4) built for MSWin32-x64-multi-thread
uSWin7pro64

Thank you.

Replies are listed 'Best First'.
Re: <JUNCTION>; how to recognize
by pryrt (Vicar) on Oct 10, 2018 at 18:53 UTC

    here is a post I have bookmarked on junctions. I've never found the Round Tuit to use that as a starting point for updating some of my personal scripts which could benefit from being able to recognize junctions1... so hopefully this link will help you get started down the right path.

    update 1: this started as a fully fledged thought, but apparently didn't get fully typed: "...recognize junctions, so I don't have the expertise to help you any further... so hopefully..."

      Following my link, and doing some more research, I eventually found https://github.com/dagolden/Path-Tiny/issues/160, which gave a function which spawns out to the cmd.exe DIR /AL command to find junctions and symlinks: so that could work. But it also pointed to Win32API::File, which has GetFileAttributes() and the FILE_ATTRIBUTE_REPARSE_POINT constant, which yields a solution for recognizing/identifying windows junctions:

      use Win32API::File qw'GetFileAttributes :FILE_ATTRIBUTE_'; sub isjunc { return (GetFileAttributes($_[0]) & FILE_ATTRIBUTE_REPARSE_POINT == + FILE_ATTRIBUTE_REPARSE_POINT) ? 1 : 0; }

      (I know, it could be simplified to sub isjunc { GetFileAttributes($_[0]) & FILE_ATTRIBUTE_REPARSE_POINT }, but I like making things more explicit.)

Re: <JUNCTION>; how to recognize
by roboticus (Chancellor) on Oct 10, 2018 at 20:29 UTC

    fatkatie:

    I don't know of any current perl modules or API that would let you work with junctions. If you can't use "dir /aL" to find the information you want, then try Googling "reparse_point", as it seems that Junctions are a specialization of Windows Reparse Points.

    I did a little work with them a couple years ago, but didn't dig into it too deeply. If you're just wanting to detect whether a file is a reparse point, though, you should be able to do so with Inline::C. A little of the C code I used to detect reparse points is:

    #include <windows.h> #include <winbase.h> int is_reparse_point(const char *file_name) { WIN32_FIND_DATA file_data; HANDLE fHandle = FindFirstFile(file_name, &file_data); // If we can't open the file handle, we'll just say it's not a rep +arse point if (fHandle == INVALID_HANDLE_VALUE) return 0; // Convert the bit into a 0/1 value return !!(fHandle.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) +; }

    Note: I just trimmed this out of an old project, and I don't have the time right now to put it together into a simple perl module, but if you want to pursue this, ping me if you have any troubles, and I'll lend a hand.

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

Re: <JUNCTION>; how to recognize
by huck (Vicar) on Oct 10, 2018 at 20:30 UTC

    Mark Russinovich wrote a JUNCTION tool, more info at https://docs.microsoft.com/en-us/sysinternals/downloads/junction. Ii>" Junction not only allows you to create NTFS junctions, it allows you to see if files or directories are actually reparse points. Reparse points are the mechanism on which NTFS junctions are based,"</i?

Re: <JUNCTION>; how to recognize
by BillKSmith (Parson) on Oct 10, 2018 at 19:29 UTC
    A JUNCTION is similar to a symbolic link. So far, I have not found any window user documentation for either one. (I believe that they are behind much of the magic in windows explorer.) Cmd.exe does not appear to support either one very well, if at all. You have discovered what I would call a bug in the windows dir command. Pure perl is not any better. I would expect the file test operator to treat them like UNIX symbolic links, but perl knows that this is not quite right.
    Bill
Re: <JUNCTION>; how to recognize
by LanX (Bishop) on Oct 10, 2018 at 18:50 UTC
    Dunno what a junction is, but did you already try stat ?

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Re^2: <JUNCTION>; how to recognize
by 3dbc (Monk) on Oct 12, 2018 at 13:42 UTC
    You're asking a windows question on perlmonks, i did a quick search on google "display junctions command prompt" and pulled up 'junction -s c:\' I'd give that a whirl in your code.

    2018-10-20 Athanasius reparented

    - 3dbc
      I think you replied to wrong node, .... considered your post to be reparented to the OP.

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1223819]
Approved by haukex
Front-paged by haukex
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (2)
As of 2018-10-21 05:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When I need money for a bigger acquisition, I usually ...














    Results (119 votes). Check out past polls.

    Notices?