Delphi文件管理函数Word格式.docx

上传人:b****3 文档编号:15807720 上传时间:2022-11-16 格式:DOCX 页数:11 大小:19.48KB
下载 相关 举报
Delphi文件管理函数Word格式.docx_第1页
第1页 / 共11页
Delphi文件管理函数Word格式.docx_第2页
第2页 / 共11页
Delphi文件管理函数Word格式.docx_第3页
第3页 / 共11页
Delphi文件管理函数Word格式.docx_第4页
第4页 / 共11页
Delphi文件管理函数Word格式.docx_第5页
第5页 / 共11页
点击查看更多>>
下载资源
资源描述

Delphi文件管理函数Word格式.docx

《Delphi文件管理函数Word格式.docx》由会员分享,可在线阅读,更多相关《Delphi文件管理函数Word格式.docx(11页珍藏版)》请在冰豆网上搜索。

Delphi文件管理函数Word格式.docx

\temp'

ifnotDirectoryExists(dir)then

//如果文件夹不存在

//删除文件DeleteFile;

Windows.DeleteFile

//DeleteFile(f);

//返回Boolean

//或者用系统API:

Windows.DeleteFile(PChar(f));

//删除文件夹RemoveDir;

RemoveDirectory

RemoveDir(dir);

//或者用系统API:

RemoveDirectory(PChar(dir));

//获取当前文件夹GetCurrentDir

=GetCurrentDir;

ShowMessage(dir);

//C:

\DocumentsandSettings\wy\MyDocuments\RADStudio\Projects

//设置当前文件夹SetCurrentDir;

ChDir;

SetCurrentDirectory

ifSetCurrentDir(dir)then

ShowMessage(GetCurrentDir);

//c:

\temp

//或者

ChDir(dir);

//无返回值

//也可以使用API:

SetCurrentDirectory(PChar(Dir));

//获取指定驱动器的当前路径名GetDir

b:

Byte;

b:

=0;

GetDir(b,dir);

//

//第一个参数:

1、2、3、4...分别对应:

A、B、C、D...

//0是缺省驱动器

//文件改名RenameFile

OldName,NewName:

OldName:

\temp\Old.txt'

NewName:

\temp\New.txt'

ifRenameFile(OldName,NewName)then

ShowMessage('

改名成功!

'

);

//也可以:

SetCurrentDir('

Old.txt'

New.txt'

//建立文件夹CreateDir;

CreateDirectory;

ForceDirectories

\temp\delphi'

CreateDir(dir);

//也可以直接用API:

CreateDirectory(PChar(dir),nil);

//如果缺少上层目录将自动补齐:

\temp\CodeGear\Delphi\2007\万一'

ForceDirectories(dir);

//删除空文件夹RemoveDir;

//建立新文件FileCreate

FileName:

i:

Integer;

FileName:

\temp\test.dat'

i:

=FileCreate(FileName);

ifi>

0then

新文件的句柄是:

'

+IntToStr(i))

else

创建失败!

//获取当前文件的版本号GetFileVersion

s:

s:

C:

\WINDOWS\notepad.exe'

=GetFileVersion(s);

//如果没有版本号返回-1

ShowMessage(IntToStr(i));

//327681这是当前记事本的版本号(还应该再转换一下)

//获取磁盘空间DiskSize;

DiskFree

r:

Real;

r:

=DiskSize(3);

//获取C:

总空间,单位是字节

=r/1024/1024/1024;

Str(r:

0:

2,s);

//格式为保留两位小数的字符串

C盘总空间是:

+s+'

GB'

ShowMessage(s);

//xx.xxGB

=DiskFree(3);

可用空间

C盘可用空间是:

//查找一个文件FileSearch

FileName,Dir,s:

notepad.exe'

Dir:

\windows'

=FileSearch(FileName,Dir);

ifs<

>

then

ShowMessage(s)//c:

\windows\notepad.exe

没找到'

//搜索文件FindFirst;

FindNext;

FindClose

sr:

TSearchRec;

//定义TSearchRec结构变量

Attr:

//文件属性

//要搜索的内容

List:

TStringList;

//存放搜索结果

\windows\*.txt'

Attr:

=faAnyFile;

//文件属性值faAnyFile表示是所有文件

List:

=TStringList.Create;

//List建立

ifFindFirst(s,Attr,sr)=0then//开始搜索,并给sr赋予信息,返回0表示找到第一个

repeat//如果有第一个就继续找

List.Add(sr.Name);

//用List记下结果

until(FindNext(sr)<

0);

//因为sr已经有了搜索信息,FindNext只要这一个参数,返回0表示找到

FindClose(sr);

//需要结束搜索,搜索是内含句柄的

ShowMessage(List.Text);

//显示搜索结果

List.Free;

//释放List

//更多注释:

//TSearchRec结构是内涵文件大小、名称、属性与时间等信息

//TSearchRec中的属性是一个整数值,可能的值有:

//faReadOnly1只读文件

//faHidden2隐藏文件

//faSysFile4系统文件

//faVolumeID8卷标文件

//faDirectory16目录文件

//faArchive32归档文件

//faSymLink

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 医药卫生 > 基础医学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1