有关文件操作的问题

Firec 2002-11-13 05:37:45
如何取消一个文件的只读、隐藏等属性?
...全文
46 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
柯嘉 2002-11-14
  • 打赏
  • 举报
回复
// The following code will change the file autoexec.bat's attribute
#include <stdio.h>

int main(void)
{
FILE *in, *out;

if ((in = fopen("\\AUTOEXEC.BAT", "rt"))
== NULL)
{
fprintf(stderr, "Cannot open input file.\n");
return 1;
}

if ((out = fopen("\\AUTOEXEC.BAK", "wt"))
== NULL)
{
fprintf(stderr, "Cannot open output file.\n");
return 1;
}

while (!feof(in))
fputc(fgetc(in), out);

fclose(in);

fclose(out);
return 0;
}
/*
r Open for reading only.
w Create for writing. If a file by that name already exists, it will be overwritten.
a Append; open for writing at end-of-file or create for writing if the file does not exist.
r+ Open an existing file for update (reading and writing).
w+ Create a new file for update (reading and writing). If a file by that name already exists, it will be overwritten.
a+ Open for append; open (or create if the file does not exist) for update at the end of the file.
*/
yang6130 2002-11-13
  • 打赏
  • 举报
回复
filesetattr((filegetattr(sFileName)) and (not faHidden) and (not faReadonly ));
shuixin13 2002-11-13
  • 打赏
  • 举报
回复
变通一下吧

WINEXEC('ATTRIB -H -R C:\1.TXT',SW_HIDE)

:》

1,184

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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