这是我写的一个代码,它的用处是计算出当前目前内的拥有hide 和system属性的文件并显示出来,从我的测试来看两个计算代码是正常的,但最后面两个if判断句却出现错误,在当前目录中无论存不存在system和hide属性文件或文件夹都不会运行msgbox函数,我自己有一个解决办法,但不是很好,希望有坛友给出问题的根源。谢谢。- dim ws,fs,current_path_files,current_path_subfolders,att,files_sum,subfolders_sum
- 'on error resume next
-
- set ws=wscript.createobject("wscript.shell")
- set fs=wscript.createobject("scripting.filesystemobject")
-
- set current_path_files=fs.getfolder(ws.CurrentDirectory).files
- set current_path_subfolders=fs.getfolder(ws.CurrentDirectory).subfolders
- '==========================================================================
- for each file in current_path_files
- 'ignore the shortcut and link
- att=file.attributes
- if att=4+2 or att=4+2+1 or att=4+2+32 or att=4+2+32+1 then
- files_sum=files_sum & file.name & vbnewline
- end if
- next
-
- for each subfolder in current_path_subfolders
- 'ignore the shortcut and link
- att=subfolder.attributes
- if att=4+2 or att=4+2+16 or att=4+2+16+1 then
- subfolders_sum=subfolders_sum & subfolder.name & vbnewline
- end if
- next
- '==========================================================================
- if files_sum <> "" then
- msgbox files_sum,,"Exist Hide and System file(s):"
- end if
-
- if folders_sum <> "" then
- msgbox subfolders_sum,,"Exist Hide and System folder(s):"
- end if
复制代码
[ 本帖最后由 s700800900 于 2010-6-20 23:48 编辑 ]
作者: zmh886 时间: 2010-6-20 19:54 标题: 使用挺正常的
- dim ws,fs,current_path_files,current_path_subfolders,att,files_sum,subfolders_sum
- 'on error resume next
-
- set ws=wscript.createobject("wscript.shell")
- set fs=wscript.createobject("scripting.filesystemobject")
-
- set current_path_files=fs.getfolder(ws.CurrentDirectory).files
- set current_path_subfolders=fs.getfolder(ws.CurrentDirectory).subfolders
- '==========================================================================
- for each file in current_path_files
- 'ignore the shortcut and link
- att=file.attributes
- if att=4+2 or att=4+2+1 or att=4+2+32 or att=4+2+32+1 then
- files_sum=files_sum & file.name & vbnewline
- end if
- next
-
- for each subfolder in current_path_subfolders
- 'ignore the shortcut and link
- att=subfolder.attributes
- if att=4+2 or att=4+2+16 or att=4+2+16+1 then
- subfolders_sum=subfolders_sum & subfolder.name & vbnewline
- end if
- next
- '==========================================================================
- if files_sum <> "" then
- msgbox files_sum,,"Exist Hide and System file(s):"
- end if
-
- if subfolders_sum <> "" then
- msgbox subfolders_sum,,"Exist Hide and System folder(s):"
- end if
复制代码
作者: zqz0012005 时间: 2010-6-20 20:54
虽然各种手册都说了最好在代码中加上Option Explicit 语句,但由于vbs一般比较短小,很难出现变量名写错的情况,且为了简洁,一般不会用它。今天终于出了一个这样的错误(太难得了,几乎没碰到过)
最后一个if语句中,folders_sum -> subfolders_sum
另外,属性比较最好用位运算:if (att AND 6) <> 0 then
作者: s700800900 时间: 2010-6-20 23:48
啊。。。哭 了都,原来是变量写错了,,,想了几天这个问题白想了。 T_T。
谢谢啊。。。终于明白了,在使用之前要定义变量是多么的重要。
欢迎光临 批处理之家 (http://bathome.net./) |
Powered by Discuz! 7.2 |