Forum > General
FindAllFiles not working on Ubuntu Folders
KarenT:
Hello,
Just when I thought FindAllFiles was a joy to use, I tried to gather files in a Linux-Hidden Folder. It returns zero files.
/home/karen/.config
Is there a workaround for "dot" files and folders?
Not sure if I need first to do something to make them visible to Lazarus/FPC, or whether the "dot" is irritating enough to FindAllFiles for it to ignore my request.
{edit}
It is definitely the "dot" causing an issue.
I found a Peter Below Folder scan function and it returns the Files, but no folders within, but it also struggles with file-names with no Extension.
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function ScanDrive(aPath, aMask: String; aList: TStringList): Boolean; function ScanDirectory(var Path: String ): Boolean; Var SRec: TSearchRec; pathlen: Integer; res: Integer; Begin pathlen:= Length(path); { first pass, files } res := FindFirst( path+aMask, faAnyfile, SRec ); If res = 0 Then try while res = 0 do begin aList.Add( path + SRec.Name ); res := FindNext(SRec); Application.ProcessMessages; end; finally FindClose(SRec) end; Result := not (FileScanAborted or Application.Terminated); If not Result Then Exit; {second pass, directories} res := FindFirst( path+'*.*', faDirectory, SRec ); If res = 0 Then try While (res = 0) and Result Do Begin If ((Srec.Attr and faDirectory) = faDirectory) and (Srec.name <> '.') And (Srec.name <> '..') Then Begin path := path + SRec.name + '\'; Result := ScanDirectory( path ); SetLength( path, pathlen ); End; res := FindNext(SRec); End; finally FindClose(SRec) end; End;begin FileScanAborted:=False; Screen.Cursor:=crHourglass; try Result:=ScanDirectory(aPath); finally Screen.Cursor:=crDefault end;end;
Xor-el:
although I have not used this personally, Ted Smith (Gizmo) uses this unit in his awesome hashing program (quickhash) and it seems to work well.
Gizmo:
You have to modify the unit slighty. I created an "enhanced" version of it (with the help of Engkin and Bart) which is part of QuickHash (https://github.com/tedsmith/quickhash/blob/master/FindAllFilesEnhanced.pas)
and then you can use it as follows for Linux to find hidden data (as seen here https://github.com/tedsmith/quickhash/blob/master/unit2.pas#L1745) :
--- Code: ---TotalFilesToExamine := FindAllFilesEx(Foldername, '*', False, True);
--- End code ---
Thanks Xor-el for your kind words :-) Base64 decoding is coming soon, and implemented into the latest master commit.
KarenT:
--- Quote from: Gizmo on July 22, 2017, 05:20:34 pm ---You have to modify the unit slighty. I created an "enhanced" version of it (with the help of Engkin and Bart) which is part of QuickHash (https://github.com/tedsmith/quickhash/blob/master/FindAllFilesEnhanced.pas)
--- End quote ---
Thank you Xor-el and Gizmo. I added in FindAllFilesEx and it works better, but, not sure yet what is missing as my test list for .config shows 160 Files+Folders, but using Nautilus and Properties for .config it shows 282 items.
Looks like 122 Folders and/or Files have gone missing.
I thought I would jump back here in case I am doing something wrong before starting to list and count everything. I tried
slFiles:=FindAllFilesEx('/home/karen/.config/','*',True,True); <-- returned 160
and
slFiles:=FindAllFilesEx('/home/karen/.config/','*.*',True,True); <-- retrned 134
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---implementation {$R *.lfm} { TForm1 }uses LazUTF8Classes, FindAllFilesEnhanced;var slFiles : TStringListUTF8; procedure TForm1.Button1Click(Sender: TObject);begin slFiles:=TStringListUTF8.Create; slFiles:=FindAllFilesEx('/home/karen/.config/','*',True,True); lb1.Items.Assign(slFiles); slFiles.Free; lbl1.Caption:=IntToStr(lb1.Items.Count);end;
JuhaManninen:
--- Quote from: Gizmo on July 22, 2017, 05:20:34 pm ---You have to modify the unit slighty. I created an "enhanced" version of it (with the help of Engkin and Bart) which is part of QuickHash (https://github.com/tedsmith/quickhash/blob/master/FindAllFilesEnhanced.pas)
--- End quote ---
Your function has parameter IncludeHiddenDirs but it is not used. How can it work?
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function FindAllFilesEx(const SearchPath: string; SearchMask: string; SearchSubDirs: boolean; IncludeHiddenDirs: boolean): TStringListUTF8;var Searcher: TListFileSearcher;begin Result := TStringListUTF8.Create; Searcher := TListFileSearcher.Create(Result); Searcher.DirectoryAttribute := Searcher.DirectoryAttribute or faHidden; try Searcher.Search(SearchPath, SearchMask, SearchSubDirs); finally Searcher.Free; end;end;The FindAllFiles found in LazUtils / FileUtil has parameter "DirAttr: Word" which supports all attributes including faHidden.
It should work without copying and modifying the code. ... or maybe I don't fully understand the issue.
BTW, you can now use a Delphi compatible TStringList instead of TStringListUTF8 without worries.
Navigation
[0] Message Index
[#] Next page