09-20-2016, 08:16 AM
Function GetFilesInFolderExcept
example - exclude folders "Debug" and "Release" in any depth
Macro Macro522
;/
function ARRAY(str)&a $parentFolder [$filenamePattern] [$exceptPattern] [flags] [getProp] ;;flags: 0 files, 1 folders, 2 any, 4 +subfolders, 8 only subfolders, 32 skip symbolic-link subfolders, 64 skip hidden-system, 0x10000 regular expression, 0x20000 compare relative path, 0x100000 exceptPattern regular expression, 0x200000 exceptPattern compare relative path. getProp: 1 size, 2 time modified, 3 time created, 4 time accessed, 0x100 (flag) don't need folder size
;Gets full paths of files in a folder.
;a - variable for results.
;parentFolder - full path of the folder. Can end with \.
;filenamePattern - if used and not "", gets only files that match filenamePattern. Else gets all files.
;;;Can be full filename, filename with <help #IDP_WILDCARD>wildcard characters</help> (*?), or regular expression (flag 0x10000).
;;;Can be relative path (flag 0x20000).
;;;Case insensitive.
;exceptPattern - if used and not "", skips files that match exceptPattern.
;;;Can be full filename, filename with <help #IDP_WILDCARD>wildcard characters</help> (*?), or regular expression (flag 0x100000).
;;;Can be relative path (flag 0x200000).
;;;Case insensitive.
;;;Note: flags 0x10000/0x20000 are for filenamePattern; flags 0x100000/0x200000 are for exceptPattern.
;flags:
;;;0, 1, 2 - file/folder type. If 0, gets only files. If 1 - only folders. If 2 - all.
;;;4 - also get files in subfolders.
;;;8 - get files only in subfolders, not in this folder.
;;;32 (QM 2.4.0) - don't get files in subfolders that have attribute FILE_ATTRIBUTE_REPARSE_POINT. It is used for symbolic links, junctions and volume mount points, that actually are not subfolders of that folder.
;;;64 (QM 2.4.0) - don't get hidden system files and folders (eg thumbnail cache files).
;;;0x10000 - filenamePattern is regular expression. Note: if need \ characters (if flag 0x20000), use \\.
;;;0x20000 - filenamePattern is path relative to parentFolder. Example: "subfolder\*\*.txt". Will be compared with whole relative paths of files, not just with filenames.
;getProp (QM 2.3.5) - prepend a file property to the path (in a), like "1000 c:\file.txt".
;;;File size is in bytes.
;;;File times are in FILETIME/DateTime format, UTC.
;;;To sort the array by a file property (or just by name, if getProp not used): a.sort(8)
;;;To get the number and path string: see example.
;;;File access time auto-updating on most computers is disabled, therefore it can be useful only if set explicitly.
;See also: <FE_Dir>.
a=0
str s.expandpath(parentFolder)
s.dospath(s 1)
s+iif((s.end("\")||!s.len) "*" "\*")
int isfp=!empty(filenamePattern)
int isep=!empty(exceptPattern)
int getPropFlags=getProp&~255; getProp&255
Dir d; lpstr sPath ss
foreach(d s FE_Dir flags&0xff)
,if isfp
,,if(flags&0x20000) ss=d.RelativePath; else ss=d.FileName
,,if(flags&0x10000) if(findrx(ss filenamePattern 0 1)<0) continue
,,else if(!matchw(ss filenamePattern 1)) continue
,if isep
,,if(flags&0x200000) ss=d.RelativePath; else ss=d.FileName
,,if(flags&0x100000) if(findrx(ss exceptPattern 0 1)>=0) continue
,,else if(matchw(ss exceptPattern 1)) continue
,
,sPath=d.FullPath
,if getProp
,,long x
,,sel getProp
,,,case 1 if(getPropFlags&0x100 and d.IsFolder) x=0; else x=d.FileSize
,,,case 2 x=d.TimeModifiedUTC
,,,case 3 x=d.TimeCreatedUTC
,,,case 4 x=d.TimeAccessedUTC
,,,case else end ERR_BADARG
,,a[].from(x " " sPath)
,else a[]=sPath
err+ end _error ;;error in rxexample - exclude folders "Debug" and "Release" in any depth
Macro Macro522
