请问如何实现这个VB程序

来源:百度知道 编辑:UC知道 时间:2024/06/08 23:33:41
Open "NoViewOnDrive.bat" For Append As #8
Print #8, "del NoViewOndrive.bat /q"
Close #8
Shell "NoViewOndrive.bat "
这是一个生成批处理然后运行的程序
如何实现这样的功能: 如果当前盘符下有NoViewOndrive.bat 这个文件就生成NoViewOndrive1.bat 然后再运行NoViewOndrive1.bat 如果当前盘有 NoViewOndrive.bat和NoViewOndrive1.bat文件 则生成NoViewOndrive2.bat
依此类推 总之就是不要覆盖原有的文件
能不能解释一下呢 谢谢

dim fStr as string

fstr="NoViewOndrive.bat"
do while dir(fstr)<>""
i=i+1
fstr=="NoViewOndrive" & i & ".bat"
loop
......

楼上代码基本正确,我给你解释下:dir()是查找目录下是否有符合括号内内容的文件存在,如果返回为""则没有,所以
do while dir(fstr)<>""
...
loop
反复执行,就是为了不断让i=i+1,以获得一个还不存在的数字i
loop之后的...写上你原有程序就可以了,

先用dir判断文件是否存在