如何在pb中建立和删除子目录
编号:QA002662
建立日期: 2000年3月2日 最后修改日期:2000年3月2日
所属类别:
彭定友:
编程工具: PB7
操作系统: WIN98
如何在pb中设置搜索路径;确定应用程序运行的当前路径;如何建立和删除子目录?
回答:
用 WINAPI 实现:
1. 声明本地外部函数(Local External Function):
FUNCTION ulong SetCurrentDirectory(ref string lpPathName) LIBRARY "kernel32.dll" ALIAS FOR "SetCurrentDirectoryA"
FUNCTION ulong CreateDirectory(ref string lpPathName,ref SECURITY_ATTRIBUTES lpSecurityAttributes) LIBRARY "kernel32.dll" ALIAS FOR "CreateDirectoryA"
FUNCTION ulong RemoveDirectory(ref string lpPathName) LIBRARY "kernel32.dll" ALIAS FOR "RemoveDirectoryA"
FUNCTION ulong DeleteFile(ref string lpFileName) LIBRARY "kernel32.dll" ALIAS FOR "DeleteFileA"
2. 定义一个结构(全局), security_attributes
(在WIN9X 中用不到,但要定义,在WINNT中用到)
nlenth unsignedlong
lpsecuritydescriptor unsignedlong
binherithandle boolean
3. 调用以上 API 函数实现 (注意调用时函数名大小写):
string ls_currentpath, ls_newdirectory, ls_removedirectory
security_attributes lstr_securityattrib
// Set The Current Path, the path should exist,
// If Failure, return 0
ls_currentpath = 'c:\Program files\powersoft'
SetCurrentDirectory(ls_currentpath)
// Create New Directory, Support Long File Name
ls_newdirectory = 'c:\it is new_Directory'
CreateDirectory(ls_newdirectory, lstr_securityattrib)
// Remove Directory,
// Directory should exist and be empty (no files)
ls_removedirectory = 'c:\removedirectory'
RemoveDirectory(ls_removedirectory)
// If the Directory is not empty,
// use DeleteFile to delete files first.
此问题由无名是我回答。
| |
|
|
| |
|
|