如何删除Windows目录下的指定文件

swlove 2007-01-27 09:28:55
比如删除 C:\WINDOWS\NOTEPAD.EXE

这样写对不?

var WinPath: array[0..255] of Char;

begin

GetWindowsDirectory(WinPath, 256);
DeleteFile(Pchar(WinPath)+'Notepad.exe');

end;
...全文
133 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
swlove 2007-01-27
  • 打赏
  • 举报
回复
明白了...

看来对基础语法还是不熟悉,寒假要好好看看基础的了
dBASEIII 2007-01-27
  • 打赏
  • 举报
回复
PChar是指针类型,当然不能直接与字符串类型进行 + 的运算

GetWindowsDirectory(WinPath, 256);后,WinPath的前几个元素的内容是C:\windows这样(假设),你可以Showmessage(string(winpath));看一下。要生成c:\windows\notepad.exe这样的字串,当然要 + '\notepad.exe'了
swlove 2007-01-27
  • 打赏
  • 举报
回复
为什么用Pchar不行,而要用string,而且要加“\”?
swlove 2007-01-27
  • 打赏
  • 举报
回复
成功,接分

不过能否解释下,这样写的语法依据是 ?
dBASEIII 2007-01-27
  • 打赏
  • 举报
回复
var WinPath: array[0..255] of Char;

begin

GetWindowsDirectory(WinPath, 256);

DeleteFile(string(winpath)+'\Notepad.exe');
end;
dBASEIII 2007-01-27
  • 打赏
  • 举报
回复
var WinPath: array[0..255] of Char;
begin
GetWindowsDirectory(WinPath, 256);
DeleteFile(Pchar(WinPath)+'\Notepad.exe');
~~~~
end;

16,748

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧