Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Enumerate Files returning duplicates
#1
I am enumerating a directory through the dialog but it is returning different paths to the same files.
Macro playground
Code:
Copy      Help
Dir d
foreach(d "C:\*" FE_Dir 4)
,str path=d.FileName(1)
,out path

For example, every file in My Documents is returning 4 times

C:\Documents and Settings\Eric\My Documents\temp Crypt\data\textStorage.dat
C:\Users\Eric\My Documents\temp Crypt\data\textStorage.dat
C:\Documents and Settings\Eric\Documents\temp Crypt\data\textStorage.dat
C:\Users\Eric\Documents\temp Crypt\data\textStorage.dat

I think this is related to special folders but I don't see how to exclude them
#2
Probably there are symbolic links. A symbolic link is similar to a shortcut (.lnk) file. Unlike with a shortcut, FE_Dir and most Windows API functions see the symbolic link as it would be a real folder, and enumerates files in it. Therefore FE_Dir can enter the same real folder 2 or more times (directly and through symbolic links).

FE_Dir and other QM functions don't have an option to skip symbolic links. Need to create new function, much work, I cannot find an easy workaround. Would need to skip folders that have attribute FILE_ATTRIBUTE_REPARSE_POINT. Probably will add such option in next QM.

Most symbolic links are hidden, unless unchecked "Hide protected OS files" in Folder Options.
Macro Show symbolic links
Code:
Copy      Help
;This macro shows all symbolic links in C:\.
;If black, FE_Dir will get files in the target folder. If red, will not get.

out
Dir d
foreach(d "C:\*" FE_Dir 1|4)
,int a=d.FileAttributes
,if(a&FILE_ATTRIBUTE_REPARSE_POINT)
,,str s=d.FileName(1)
,,WIN32_FIND_DATA fd
,,int fh=FindFirstFile(F"{s}\*" &fd)
,,if(fh=-1) out F"<><c 0xff>{s}        ({_s.dllerror})</c>"
,,else FindClose(fh); out s


Forum Jump:


Users browsing this thread: 1 Guest(s)