Delphi——FindFirst学习

FindFirst在SysUtils中声明 原型为
Fucntion FindFirst(const Path:String;Attr:Integer;Var F:TSearchRec):Integer;

描述:
从指定的目录中搜索第一个给定属性文件实例
返回结果保存到参数F中,F参数是一个文件结构包含文件信息
成功返回0,否则返回错误代码

参数Path:包含路径和搜索模糊文件名,包括通配符: './text/*.*'搜索test目录下的全部文件
参数Attr:指定文件属性类型
     faReadOnly:只读文件
     faHidden:隐藏文件
     faSysFile:系统文件
     faVolumeID:卷标文件
     faDirectory:目录文件
     faArchive:归档文件//压缩文件
     faAnyFile:任何文件

Attr可以通过组合使用 faReadOnly+faSysFile

注意:
使用FindFist是要分配内存的使用完之后必须用FindClose关闭
一些属性只能在特定的平台上使用 faVolumeID和faArchivei不能在Unix和mac上使用

//遍历文件夹下所有文件
function TForm1.GetFileList(ASourFile: string): TStringList;
var sour_path,sour_file: string;
    TmpList:TStringList;
    FileRec:TSearchrec;
begin
   sour_path:=ExtractFilePath(ASourFile);
   sour_file:=ExtractFileName(ASourFile);
   TmpList:=TStringList.Create;
   TmpList.Clear;
   if DirectoryExists(sour_path) then
   begin
     if FindFirst(sour_path+sour_file,faAnyfile,FileRec) = 0 then
     repeat
        if ((FileRec.Attr and faDirectory) = 0) then
           begin
             TmpList.Add(sour_path+FileRec.Name);
           end;
     until FindNext(FileRec)<>0;
     SysUtils.FindClose(FileRec);
   end;
   result := TmpList;
end;

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Creating Windows CreateMDIWindow CreateWindow CreateWindowEx RegisterClass RegisterClassEx UnregisterClass Message Processing BroadcastSystemMessage CallNextHookEx CallWindowProc DefFrameProc DefMDIChildProc DefWindowProc DispatchMessage GetMessage GetMessageExtraInfo GetMessagePos GetMessageTime GetQueueStatus InSendMessage PeekMessage PostMessage PostQuitMessage PostThreadMessage RegisterWindowMessage ReplyMessage SendMessage SendMessageCallback SendMessageTimeout SendNotifyMessage SetMessageExtraInfo SetWindowsHookEx TranslateMessage UnhookWindowsHookEx WaitMessage Window Information AnyPopup ChildWindowFromPoint ChildWindowFromPointEx EnableWindow EnumChildWindows EnumPropsEx EnumThreadWindows EnumWindows FindWindow FindWindowEx GetClassInfoEx GetClassLong GetClassName GetClientRect GetDesktopWindow GetFocus GetForegroundWindow GetNextWindow GetParent GetProp GetTopWindow GetWindow GetWindowLong GetWindowRect GetWindowText GetWindowTextLength IsChild IsIconic IsWindow IsWindowEnabled IsWindowUnicode IsWindowVisible IsZoomed RemoveProp SetActiveWindow SetClassLong SetFocus SetForegroundWindow SetParent SetProp SetWindowLong SetWindowText WindowFromPoint Processes and Threads CreateEvent CreateMutex CreateProcess CreateSemaphore CreateThread DeleteCriticalSection DuplicateHandle EnterCriticalSection ExitProcess ExitThread GetCurrentProcess GetCurrentProcessId GetCurrentThread GetCurrentThreadId GetExitCodeProcess GetExitCodeThread GetPriorityClass GetThreadPriority GetWindowThreadProcessId InitializeCriticalSection InterlockedDecrement InterlockedExchange InterlockedIncrement LeaveCriticalSection OpenEvent OpenMutex OpenProcess OpenSemaphore PulseEvent ReleaseMutex ReleaseSemaphore ResetEvent ResumeThread SetEvent SetPr

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值