ListFiles - scan for files easily

Share your advanced PureBasic knowledge/code with the community.
User avatar
kenmo
Addict
Addict
Posts: 2033
Joined: Tue Dec 23, 2003 3:54 am

Re: ListFiles - scan for files easily

Post by kenmo »

Just a heads-up, I replaced the code in the original post with an updated version.

Changes:

Two new flags: NoHidden (excludes hidden files from results) and HiddenOnly (self explanatory)

Slightly changed the behavior of the AllowNoExt flag. Now, setting that flag and not specifying any other file types allows you to scan ONLY for files without extensions (previously you would have to set the flag and specify at least one extension, like *.faketype ).
kinglestat
Enthusiast
Enthusiast
Posts: 746
Joined: Fri Jul 14, 2006 8:53 pm
Location: Malta
Contact:

Re: ListFiles - scan for files easily

Post by kinglestat »

Thanks for this
Very nicely presented
Was going to code something simple and found this nice solution
Beer's on me if you are ever around!
I may not help with your coding
Just ask about mental issues!

http://www.lulu.com/spotlight/kingwolf
http://www.sen3.net
forumuser
User
User
Posts: 98
Joined: Wed Apr 18, 2018 8:24 am

Re: ListFiles - scan for files easily

Post by forumuser »

@kenmo

Would it be possible to add a limitation on how deep the recursion goes?

Code: Select all

E.g.:
0 = No recursion limit
1, 2, 3, ... = Only traverse <x> subfolders deep

For example a directory structure:
R:\VPN
R:\VPN\data
R:\VPN\logs
R:\VPN\logs\provider
R:\VPN\logs\provider\1
R:\VPN\logs\provider\2

Then 1 would only recurse into these folders:
R:\VPN
R:\VPN\data
R:\VPN\logs

And 2 only into these:
R:\VPN
R:\VPN\data
R:\VPN\logs
R:\VPN\logs\provider

Etc.
Another question:
Would it be possible to present found files + folders ([x] Include folders is used)
in a way that files for a folder are always displayed first? Atm it is a purely alphabetical listing

E.g. this is the current result:

Code: Select all

R:\VPN\
R:\VPN\config.ini
R:\VPN\data\
R:\VPN\OpenVPN.exe
...
and it would be extremely nice if there was an option to display it like this:

Code: Select all

R:\VPN\
R:\VPN\config.ini
R:\VPN\OpenVPN.exe
R:\VPN\data\
...
Which means:

Code: Select all

<folder>
<folder>\<files for that folder>
<folder>\<first sub folder>
<folder>\<first sub folder>\<files for that first subfolder>
<folder>\<second sub folder>
<folder>\<second sub folder>\<files for that second subfolder>
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: ListFiles - scan for files easily

Post by Michael Vogel »

Quick and dirty to limit the search depth...

Code: Select all

			; Scan sub-folder, add sub-count to current count
			If (Recurse) And CountString(Relative,"\")<#maxdepth
				Recurse = xListFiles(Root, Relative + Name, Results(), Extensions, Flags)
				If (Recurse > 0) And depth<#maxdepth
					Count + Recurse
				EndIf
			EndIf
forumuser
User
User
Posts: 98
Joined: Wed Apr 18, 2018 8:24 am

Re: ListFiles - scan for files easily

Post by forumuser »

Thanks a lot, Michael, that solves the recursive problem for me!
User avatar
kenmo
Addict
Addict
Posts: 2033
Joined: Tue Dec 23, 2003 3:54 am

Re: ListFiles - scan for files easily

Post by kenmo »

You can also try a newer IncludeFile I wrote called "ScanFolder"

https://raw.githubusercontent.com/kenmo ... Folder.pbi

Code: Select all

Procedure.i ScanFolder(Folder.s, Flags.i = #Null, Extensions.s = "", RecurseDepth.i = 0, RegexPattern.s = "")
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: ListFiles - scan for files easily

Post by davido »

@kenmo,
Very useful. Thank you for sharing. :D
DE AA EB
forumuser
User
User
Posts: 98
Joined: Wed Apr 18, 2018 8:24 am

Re: ListFiles - scan for files easily

Post by forumuser »

Thank you kenmo!
Post Reply