如何调用用API的removedir 方法来删除不为空的目录?(100分)

  • 主题发起人 主题发起人 zzx8866
  • 开始时间 开始时间
Z

zzx8866

Unregistered / Unconfirmed
GUEST, unregistred user!
我在win32 SDK 的帮助中找到removedir,但只有其功能和参数的说明,不知它包含<br>在哪个单元。引用其它API函数也是这样,如winexec,系统总是提示undeclare.<br>如何在delphi中知道这些API函数或过程所在的单元?另外删除一批文件或一个不为空的<br>目录还有别的办法吗?<br>
 
ShFileOperation()<br>删除目录:<br><br>function DelDirectory(const Source:string): boolean;<br>var<br>&nbsp; fo: TSHFILEOPSTRUCT;<br>begin<br>&nbsp; FillChar(fo, SizeOf(fo), 0);<br>&nbsp; with fo do<br>&nbsp; begin<br>&nbsp; &nbsp; Wnd := 0;<br>&nbsp; &nbsp; wFunc := FO_DELETE;<br>&nbsp; &nbsp; pFrom := PChar(source+#0);<br>&nbsp; &nbsp; pTo := #0#0;<br>&nbsp; &nbsp; fFlags := FOF_NOCONFIRMATION+FOF_SILENT;<br>&nbsp; end;<br>&nbsp; Result := (SHFileOperation(fo) = 0);<br>end;<br><br>HeadFile那一行就表明在那个单元了。一般winuser.h表示windows。<br>实在不知道可以使用查找的方法:<br>查找文件*.pas包含文字"RemoveDir"不就知道了?<br>
 
谢谢kingron,恕我学艺不精,#0是什么意思?
 
#0表示空字符,ShFileOperation中的一个参数TSHFILEOPSTRUCT的pFrom,pTo必须用#0#0结尾。<br>看看MSDN就知道了。
 
#0表示空字符,ShFileOperation中的一个参数TSHFILEOPSTRUCT的pFrom,pTo必须用#0#0结尾。<br>看看MSDN就知道了。
 
kingron:<br>&nbsp; &nbsp; 真不好意思,我还不知道MSDN是什么东西,怎么查看?
 
MSDN就是M$出的帮助系统了。Win API和VS的帮助。
 
再来一个:copy from RxLib - FileUtil.pas<br>function ClearDir(const Path: string; Delete: Boolean): Boolean;<br>const<br>{$IFDEF WIN32}<br>&nbsp; FileNotFound = 18;<br>{$ELSE}<br>&nbsp; FileNotFound = -18;<br>{$ENDIF}<br>var<br>&nbsp; FileInfo: TSearchRec;<br>&nbsp; DosCode: Integer;<br>begin<br>&nbsp; Result := DirExists(Path);<br>&nbsp; if not Result then Exit;<br>&nbsp; DosCode := FindFirst(NormalDir(Path) + '*.*', faAnyFile, FileInfo);<br>&nbsp; try<br>&nbsp; &nbsp; while DosCode = 0 do begin<br>&nbsp; &nbsp; &nbsp; if (FileInfo.Name[1] &lt;&gt; '.') and (FileInfo.Attr &lt;&gt; faVolumeID) then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; if (FileInfo.Attr and faDirectory = faDirectory) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Result := ClearDir(NormalDir(Path) + FileInfo.Name, Delete) and Result<br>&nbsp; &nbsp; &nbsp; &nbsp; else if (FileInfo.Attr and faVolumeID &lt;&gt; faVolumeID) then begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (FileInfo.Attr and faReadOnly = faReadOnly) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FileSetAttr(NormalDir(Path) + FileInfo.Name, faArchive);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Result := DeleteFile(NormalDir(Path) + FileInfo.Name) and Result;<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; DosCode := FindNext(FileInfo);<br>&nbsp; &nbsp; end;<br>&nbsp; finally<br>&nbsp; &nbsp; FindClose(FileInfo);<br>&nbsp; end;<br>&nbsp; if Delete and Result and (DosCode = FileNotFound) and<br>&nbsp; &nbsp; not ((Length(Path) = 2) and (Path[2] = ':')) then<br>&nbsp; begin<br>&nbsp; &nbsp; RmDir(Path);<br>&nbsp; &nbsp; Result := (IOResult = 0) and Result;<br>&nbsp; end;<br>end;<br>
 
谢谢kingron和mikedeadins两位热心的朋友。<br>两种方法都可以实现,但kingron比mikedeadins的程序要简单。
 
后退
顶部