Delphi: How to process multiple files? -
How can I create a program to read the first file in Delphi 2007 and then turn it off to read the other Can I last file?
Are you trying to read every file in a directory? Try this square. This is not my original code, but I have modified it a bit more. It gives you all the filenames that match the criteria that you set in a string list that you can do with TFilestream.
unit search file; Uses interface classes; Type TFileAttrKind = (ffaReadOnly, ffaHidden, ffaSysFile, ffa directory, ffaArchive, ffaAnyFile); TFileAttr = TFileAttrKind set; TFindFile = Class (Tubect) Private S: TStringList; FSubFolder: Boolean; FAttr: TFileAttr; FPath: string; FBasePath: string; FFileMask: string; FDepth: integer; Process set path (value: string); Process file search (located in path: string); Function lotus (value: string): string; Create Public Builders (Path: String); Destruction of Destruction; Override; Function SearchForFile: TStringList; Property FileArt: TFFileAttri FATT for writing FATR; Property InSubFolders: boolean fSubFolder write fSubFolder; Property Path: Setting Path Reading FPath SetPath; Property File Mask: Read the string fFileMask; fFileMask; End; The implementation uses {$ WARN SYMBOL_PLATFORM OFF} {$ WARN UNIT_PLATFORM OFF} Windows, SysUtils, FileCtrl; Manufacturer TFindFile.Create (Path: String); Start the heritage; Create; FPath: = Path; FBasePath: = Path; File Mask: = '*. * '; FileAttr: = [ffaReadOnly, ffa directory, ffaArchive]; S: = TStringList.Create; FDepth: = -1; End; Process TFindFile.SetPath (value: string); Get started if fPath & lt; & Gt; The value starts when (value <> ">" and "DirectoryExists") then fpath: = IncludeTrailingPathDelimiter (value); End; End; TFindFile.SearchForFiles: TStringList function; Start S Try FileSearch (Path); Finally results: = s; End; End; Function TFindFile.cull (value: string): string; The result starts: = string replay (value, FBasePath, '', []); End; Destructor TFindFile.Destroy; Start s.Free; Destroys inheritance; End; Process TFindFile.FileSearch (const InPath: string); Var Rick: TSearchRec; Attr: integer; Initiation (FDeep); Try Attry: = 0; If ffaReadOnly in FileAttr, then Attr: = Attr + faReadOnly; If ffaHidden entry in fileart: = Attr + faHidden; If ffaSysFile in FileArt then Attr: = Attr + faSysFile; If FFA Directory in FileArt then Attr: = Attr + faDirectory; If FFARHV is etRR: = Etror + FARKV in FileArt; If ffaAnyFile in the file ATR, then Attr: = Attr + faAnyFile; If SysUtils.FindFirst (InPath + FileMask, Attr, Rec) = 0 then try to repeat if (Rec.Name = '.') Or (Rec.Name = '..') then continue; S.Add (cull (inPath) + Rec.Name); Unless SysUtils.FindNext (REC) & lt; & Gt; 0; Finally SysUtils.FindClose (REC); End; If not inSubFolders exit; If SysUtils.FindFirst (inPath + '*. *', FaDirectory, Rec) = 0 then try to repeat again ((Rec.Attr and faDirectory) <0> and (Rec.Name & lt; Gt; '.') And (rec.nm <> '..') then start searching the file (TrailingPathDelimiter (inPath + Rec.Name)); End; Unless SysUtils.FindNext (REC) & lt; & Gt; 0; Finally SysUtils.FindClose (REC); End; Eventually, the DCD (FDP); End; End; End.
Comments
Post a Comment