指定一个目录.把里面的所有东西删除

tmxkdldw 2006-07-16 11:13:19
我用的是pb9.0
...全文
147 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
dragon45 2006-07-17
  • 打赏
  • 举报
回复
写个批处理文件
del.bat

内容:
rmdir [drive:]path /s /Q
直接run批处理文件就行了吗
vc555 2006-07-16
  • 打赏
  • 举报
回复
先GetFolder()指定文件夹,再DirList()得到文件,最后FileDelete()删除。
圣殿骑士18 2006-07-16
  • 打赏
  • 举报
回复
循环再循环,找到每个文件,删除之
tmxkdldw 2006-07-16
  • 打赏
  • 举报
回复
谢谢楼上的。你应该是封装了。还有别的函数吧。我也没法用。

我只想实现指定一个文件,里面也许又目录,文件。目录里又包括目录,文件等。也什么许也没有。总之我想把里面的所有通通删除。只保留指定的那个目录。最后里面什么也没有就ok了。
圣殿骑士18 2006-07-16
  • 打赏
  • 举报
回复
//////////////////////////////////////////////////////////////////////////////
//
// Function: Of_filecopytr
//
// Access: Public
//
// Arguments:
// as_sourcefile: 源文件;
// as_destinationfile: 目的文件;
// ab_append: 是追加还是覆盖?;
//
// Returns: integer
// -1 失败,并中断拷贝(严重失败)
// -2 一般失败,继续拷贝
// 1 拷贝成功
//
//
//
// Description: 拷贝文件,同时也能拷贝目录下的所有文件
//
//////////////////////////////////////////////////////////////////////////////
//
// Revision History
//
// Version
//
//////////////////////////////////////////////////////////////////////////////
//
// CR 2002 - 2004
//
//////////////////////////////////////////////////////////////////////////////
long li_ret,li_rtn,lj
string ls_msg
date ld_sourcedate,ld_DestinationDate
time lt_sourcetime,lt_Destinationtime
boolean lb_readonly,lb_hidden,lb_system,lb_subdirectory,lb_archieve
string ls_subsourcespec,ls_subsourcefile,ls_subdestfile
n_cst_dirattrib lnv_dirattrib[]

li_ret=of_getfileattributes(as_sourcefile,lb_readonly,lb_hidden,lb_system,lb_subdirectory,lb_archieve)
if li_ret=-1 then
ls_msg = '~r~n'+string(datetime(today(),now()),'yyyy.mm.dd hh:mm:ss') + &
'~r~nFile ' + as_SourceFile +' in getfileattributes failed!'
FileWrite(ai_logfile,ls_msg)
return -2
end if

if lb_subdirectory then //find the directory
//create destination directory
if not directoryexists(as_destinationfile) then
li_ret=createdirectory(as_destinationfile)
end if

if li_ret=-1 then
ls_msg = '~r~n'+string(datetime(today(),now()),'yyyy.mm.dd hh:mm:ss') + &
'~r~nFile ' + as_destinationfile +' in create directory failed!'
FileWrite(ai_logfile,ls_msg)
return -2
end if

//begin copy subdiretory
ls_subsourcespec=as_sourcefile+'\*.*'
li_rtn=of_dirlist(ls_subsourcespec,0+2+4+16+32,lnv_dirattrib)
if li_rtn>0 then
for lj=1 to li_rtn
if lnv_dirattrib[lj].is_filename='[..]' then continue
if lnv_dirattrib[lj].ib_subdirectory then
ls_subsourcefile=as_sourcefile+'\'+&
mid(lnv_dirattrib[lj].is_FileName,2,len(lnv_dirattrib[lj].is_FileName) -2)
ls_subdestfile=as_destinationfile+'\'+&
mid(lnv_dirattrib[lj].is_FileName,2,len(lnv_dirattrib[lj].is_FileName) -2)
else
ls_subsourcefile=as_sourcefile+'\'+lnv_dirattrib[lj].is_FileName
ls_subdestfile=as_destinationfile+'\'+lnv_dirattrib[lj].is_FileName
end if
if of_filecopytr(ls_subsourcefile,ls_subdestfile,ab_append,ai_logfile)=-1 then return -1
next
end if

else //find the file
if not FileExists(as_SourceFile) then
ls_msg = '~r~n'+string(datetime(today(),now()),'yyyy.mm.dd hh:mm:ss') + &
'~r~nFile ' + as_SourceFile +' in INI file is not find!'
FileWrite(ai_logfile,ls_msg)
return -2
end if

of_GetLastWriteDatetime(as_SourceFile,&
ld_SourceDate,lt_SourceTime)
of_GetLastWriteDatetime(as_DestinationFile,&
ld_DestinationDate,lt_DestinationTime)

if not FileExists(as_DestinationFile) or &
(DaysAfter (ld_SourceDate,ld_DestinationDate) < 0) or &
(DaysAfter (ld_SourceDate,ld_DestinationDate) = 0 and &
SecondsAfter(lt_SourceTime,lt_DestinationTime) < 0 ) then

if not isvalid(w_copy_show) then
open(w_copy_show)
end if

w_copy_show.of_SetSource(as_SourceFile)
w_copy_show.of_SetDestination(as_DestinationFile)
of_setfileattribs(as_DestinationFile,'R-')
li_ret=of_FileCopy(as_SourceFile,as_DestinationFile,false)
if li_ret = 1 then
ls_msg = '~r~n'+string(datetime(today(),now()),'yyyy.mm.dd hh:mm:ss') + &
'~r~nCopy ' + as_SourceFile+' to '+&
as_DestinationFile + ' success!'
FileWrite(ai_logfile,ls_msg)
of_SetLastWriteDatetime(as_DestinationFile,&
ld_SourceDate,lt_SourceTime)
else
if li_ret = -1 then
ls_msg = '~r~n'+string(datetime(today(),now()),'yyyy.mm.dd hh:mm:ss') + &
'~r~n'+as_SourceFile+' open error! '
FileWrite(ai_logfile,ls_msg)
elseif li_ret = -2 then
ls_msg = '~r~n'+string(datetime(today(),now()),'yyyy.mm.dd hh:mm:ss') + &
'~r~n'+as_DestinationFile+' write error! '
FileWrite(ai_logfile,ls_msg)
end if
end if
end if
end if

return 1
  • 打赏
  • 举报
回复
学习!!
tmxkdldw 2006-07-16
  • 打赏
  • 举报
回复
楼上的有列子吗?发个给我吧
圣殿骑士18 2006-07-16
  • 打赏
  • 举报
回复
子目录删除可以用递归调用。
tmxkdldw 2006-07-16
  • 打赏
  • 举报
回复
有什么api可用
tmxkdldw 2006-07-16
  • 打赏
  • 举报
回复
里面也可能包括问见夹啊,要全部删除啊

1,079

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 相关问题讨论
社区管理员
  • 基础类社区
  • WorldMobile
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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