file loop listing the same files twice (identify redirected folders)

Get help with using AutoHotkey and its commands and hotkeys
User avatar
jeeswg
Posts: 3537
Joined: 19 Dec 2016, 01:58
Location: UK

file loop listing the same files twice (identify redirected folders)

18 Jan 2018, 10:03

- I am interested in ways to identify whether a folder is a proper folder or some kind of redirected folder.
- One way is two check the attributes of a folder and all of it's ancestor folders.

Based on this post by Builder:
Possible A_LoopFileLongPath bug - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=42891&p=194747#p194747
It also will loop over a file twice if Windows has more than one way of referencing the address....

example...
D:\Documents and Settings\Thomas\Desktop\STARTUP.ahk
D:\Users\Thomas\Desktop\STARTUP.ahk

Based on these posts by Noesis:
Possible A_LoopFileLongPath bug - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=42891&p=195003#p195003
Possible A_LoopFileLongPath bug - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=42891&p=195052#p195052

Some code to compare two folders, which doesn't help to identify folder redirection on subfolders:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus


- Btw we would probably benefit from some sort of 'A_LoopFileAttribNum' variable for file loops, to reduce overhead, if wanting to check the attributes of every file in a folder/on the hard drive for special properties.
- The attribute number should already be available in the WIN32_FIND_DATA structure that the AutoHotkey file loop uses. E.g. see this example for more details:
259-char path limit workarounds - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=26170&p=170806#p170806

- Here is an 'IsRedirected' function, although 'redirected' may or may not be the proper term for this.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Last edited by jeeswg on 18 Jan 2018, 20:33, edited 1 time in total.
Builder
Posts: 12
Joined: 20 Apr 2014, 11:31

Re: file loop listing the same files twice (identify redirected folders)

18 Jan 2018, 19:49

I tried your function...
Perhaps because it was inside a nested file loop, it got stuck. Apparently there was an issue with the while InStr.

I am uncertain of what the loop in your function was for, and I was equally uncertain of what the SplitPath was for, so I did some trimmng.

The result I arrived at works happily anywhere, whether several layers deep in a directory, or a folder in the root.

Code: [Select all] [Download] GeSHi © Codebox Plus

IsRedirected(vDir)
{
;FILE_ATTRIBUTE_REPARSE_POINT := 0x400
return (0x400 & DllCall("kernel32\GetFileAttributes", Str,vDir, UInt))
}


Incidently, the command propmt is able to distinguish links

A listing if links in a directory can be obtained by typing

dir *.* /a:L

The beauty of the information the command prompt provides here is that it not only specifies the link, it also provides the folder it links to, and the type of link
ex.
2009-07-13 10:53 PM <JUNCTION> Documents and Settings [D:\Users]
User avatar
jeeswg
Posts: 3537
Joined: 19 Dec 2016, 01:58
Location: UK

Re: file loop listing the same files twice (identify redirected folders)

18 Jan 2018, 20:52

- I'll explain a few things here, which you might know, but they are there generally for the benefit of anyone reading.

- I should warn you that I'm not sure if your simplified function would work correctly, it could give false positives, and here's why. If the function fails for some reason, the DllCall would return 0xFFFFFFFF. If you then do 0xFFFFFFFF & 0x400, that returns 0x400 which is considered as true (since it is nonzero).
- A common fail code is -1, when -1 is stored by computers, as an unsigned integer, it is usually stored as (256 to the power of n) - 1, where n is the size in bytes of the integer, which will be a hex number made entirely of F's.
- The DllCall function is passed UInt as its final parameter, hence it will return a number which is a UInt.
- The maximum value for a UInt (which is 4 bytes in size), is 0xFFFFFFFF, which is the equivalent of -1. I.e. if you start at 0, and subtract 1, you wrap around to 0xFFFFFFFF, the maximum number a UInt can store.
- In a bitwise-and comparison:

Code: [Select all] [Download] GeSHi © Codebox Plus

        0xFFFFFFFF := 11111111111111111111111111111111
0x400 := 00000000000000000000010000000000
0xFFFFFFFF & 0x400 := 00000000000000000000010000000000

- You end up with 0xFFFFFFFF & 0x400 = 0x400, and since 0x400 is not 0, AHK regards it as true.

- I believe that this simplified function would work:

Code: [Select all] [Download] GeSHi © Codebox Plus

IsRedirectedSimple(vPath)
{
vAttrib := DllCall("kernel32\GetFileAttributes", Str,vPath, UInt)
;FILE_ATTRIBUTE_REPARSE_POINT := 0x400
return !!(vAttrib & 0x400) && !(vAttrib = 0xFFFFFFFF)
}

- Here's a demonstration of how SplitPath works:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus


- I have since updated my function in my original post. It now has a DoRecurse option. By default, it will only check if the current file/folder is redirected, if recurse is allowed, it will check if any of the ancestor folders are redirected.
- Based on what Noesis said, and as shown in my example in the OP, it appears that checking a file/folder directly, to see if it is redirected, doesn't always work, if the check states that the file is not redirected, you have to check its ancestors to be sure.
User avatar
jeeswg
Posts: 3537
Joined: 19 Dec 2016, 01:58
Location: UK

Re: file loop listing the same files twice (identify redirected folders)

18 Jan 2018, 21:24

Here's a command line example that uses dir.
E.g. (your example): 2009-07-13 10:53 PM <JUNCTION> Documents and Settings [D:\Users]

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus


Return to “Ask For Help”

Who is online

Users browsing this forum: Google [Bot], Jonas353, Jovannb, MegaRookie, Noo0B, Odlanir and 47 guests