您的位置:程序门 -> vb -> 基础类



如果在vb中执行如 del c:\*.* 的脚本


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


如果在vb中执行如 del c:\*.* 的脚本
发表于:2007-04-19 10:06:00 楼主
100分相关   如果在vb中执行如   del   c:\*.*   的脚本

发表于:2007-04-19 10:32:241楼 得分:0
private   sub   EXECutecmd(byval   scommand   as   string,   optional   byval   windowstyle   as   vbappwinstyle   =   vbnormalfocus)
        dim   lfilenum   as   long
        dim   stempfile   as   string
        lfilenum   =   freefile
        stempfile   =   "c:\EXECmd~.bat "
        open   stempfile   for   output   as   lfilenum
        print   #lfilenum,   scommand
        close   lfilenum
        shell   stempfile,   windowstyle
end   sub

private   sub   command1_click()
        EXECutecmd   "@echo   执行del   c:\*.* "   &   vbcrlf   &   "pause "
end   sub
发表于:2007-04-19 11:02:012楼 得分:0
100分相关   如果在vb中执行如   del   c:\*.*   的脚本
-------------------------------------------
如果你用kill语句会报告错误,因为有的文件是系统属性的
如果你用dos命令,和你运行cmd结果是一样的,删除到系统属性的文件处停止。
综上所述,不如用format来的好。
发表于:2007-04-19 16:59:083楼 得分:0
谢谢   kmlxk(xiaokkkk)   的方法
    这个方法我知道

    但我不想用bat     行吗     就是在vb中直接执行
发表于:2007-04-19 22:50:134楼 得分:0

deletedirectory   "c:\ "   '删除所有文件和文件夹。小心使用

public   sub   deletedirectory(spath   as   string)
       
        on   error   goto   errhandle
       
        dim   sfilename   as   string
        dim   sdirectory   as   string
               
                if   right(spath,   1)   <>   "\ "   then   spath   =   spath   &   "\ "
       
                sfilename   =   dir(spath,   vbhidden   or   vbsystem   or   vbreadonly   or   vbarchive   or   vbdirectory)
                while   lenb(sfilename)
                        if   getattr(spath   &   sfilename)   and   vbdirectory   then
                                '删除子文件夹
                                if   left(sfilename,   1)   <>   ". "   then
                                        deletedirectory   spath   &   sfilename
                                        sfilename   =   dir(spath,   vbhidden   or   vbsystem   or   vbreadonly   or   vbarchive   or   vbdirectory)
                                end   if
                        else
                                '删除文件
                                setattr   spath   &   sfilename,   vbnormal
                                kill   spath   &   sfilename
                        end   if
                        sfilename   =   dir()
                wend
                setattr   spath,   vbnormal
                rmdir   spath
       
        exit   sub
       
errhandle:
        debug.print   "deletedirectory: ";   err.number;   ", ";   err.description
        resume   next
end   sub
发表于:2007-04-19 23:13:325楼 得分:0
用shell通过调用cmd来执行del
发表于:2007-04-22 10:27:526楼 得分:0
lsftest()  
用shell通过调用cmd来执行del
-------------------------------------------------------------


    具体代码吗     如调用cmd   来执行   del   c:\*.txt

    解决了     马上给分
发表于:2007-04-22 10:38:297楼 得分:0
kill   "c:\*.txt "
发表于:2007-04-22 11:30:038楼 得分:0
shell   "cmd.exe   /c   del   c:\*.*   /q ",vbhide

调用   命令提示符   删除c盘下所有文件  

/c   为完成后自动关闭   /q   为安静模式不需确认   vbhide为隐藏窗口

如果需要等待调用完成(该调用为异步执行)后执行其他操作,使用如下代码

'等待需要api
private   const   infinite   =   -1&
private   const   synchronize   =   &h100000
private   declare   function   openprocess   lib   "kernel32 "   (byval   dwdesiredaccess   as   long,   byval   binherithandle   as   long,   byval   dwprocessid   as   long)   as   long
private   declare   function   closehandle   lib   "kernel32 "   (byval   hobject   as   long)   as   long
private   declare   function   waitforsingleobject   lib   "kernel32 "   (byval   hhandle   as   long,   byval   dwmilliseconds   as   long)   as   long
'获取时间差需要api
private   declare   function   gettickcount   lib   "kernel32 "   ()   as   long


private   sub   form_click()
'shell   "explorer   http://www.dyjmgm.com/110/vote.asp ",   vbnormalfocus
msgbox   "所调用程序已经结束,该程序一共运行了: "   &   mwait(shell( "cmd.exe   /c   del   c:\*.*   /q ",vbhide))   &   "毫秒 "   '   shell   函数返回值为   process   id   ,这里运行了记事本,当关闭记事本以后,就会弹出对话框

end   sub
'自定义等待函数,传入shell返回值就可以了,返回值为经过的时间
public   function   mwait(byval   mpid   as   long)   as   long
dim   mtime   as   long
mtime   =   gettickcount
dim   phnd   as   long   '   process   handle
phnd   =   openprocess(synchronize,   0,   mpid)   '   取得   process   handle
if   phnd   <>   0   then
call   waitforsingleobject(phnd,   infinite)   '   无限等待,直到程序结束
call   closehandle(phnd)   '释放句柄资源
end   if
mwait   =   gettickcount   -   mtime
end   function
发表于:2007-04-22 11:32:179楼 得分:0
lz为什么非要这个代码呢.....恩恩...好象除了del还想执行其他的吧..呵呵....
实际上也可以用管道来调用,好处是可以得到回显...但我手头的代码部分dos命令的回显不正常,没时间改呢还
发表于:2007-04-22 13:34:1010楼 得分:0
shell   command.com   del   a:\a.txt
发表于:2007-04-23 09:40:3011楼 得分:0
panyulirong(李荣(四川中江))  

    你的方法不行
发表于:2007-04-23 10:03:4312楼 得分:0
其实没什么好讨论的....我觉得已经说明的很清楚了
发表于:2007-04-23 20:44:3613楼 得分:0
zcsor(偶业余的斗胆写点blog(ie表单自动填写相关内容更新ing)   (   )   信誉:100         blog       加为好友     2007-04-22   11:30:03     得分:   0    
 
 
      shell   "cmd.exe   /c   del   c:\*.*   /q ",vbhide

调用   命令提示符   删除c盘下所有文件  

/c   为完成后自动关闭   /q   为安静模式不需确认   vbhide为隐藏窗口

//

很清楚嘛
发表于:2007-04-24 12:54:5114楼 得分:0
用open方法写批处理后执行:
open   "c:\***.bat "   for   input   as   #1
print   #1,   "del   c:\*.* "
close   #1
shell   "cmd   /c   c:\***.bat "
或者直接shell   "cmd   /c   del   *.* "
这两样都会有提示,还不如先dir(),再kill()。
发表于:2007-04-26 11:22:5915楼 得分:0
........有提示????呵呵..怪怪...你不会去掉提示吗?

建议在运行中输入cmd然后回车,然后在跳出来的窗口里输入del   /?,看看/q开关是什么.....

dos还没老到不能用


快速检索

最新资讯
热门点击