一个VB做的程序,要在程序启动时:
1、检查D:\是否存在一个名为TP的文件夹,如果没有创建一个。
2、检查D:\TP\是否存在一个名为1.txt的文件,如果没有创建一个。
麻烦写一下代码。
第1个回答 2009-12-31
If Dir("D:\TP", vbDirectory) = "" Then
MkDir ("D:\TP")
Else
MsgBox "文件夹已存在"
End If
Open "d:\tp\1.txt" For Append As #1 '检测d:\tp\1.txt是否存在,不存在则创建,存在则打开
Close #1 '关闭1.txt 备注:此处的打开关闭 并不在Windows任务栏显示
写完测试过得,放心使用
MkDir ("D:\TP")
Else
MsgBox "文件夹已存在"
End If
Open "d:\tp\1.txt" For Append As #1 '检测d:\tp\1.txt是否存在,不存在则创建,存在则打开
Close #1 '关闭1.txt 备注:此处的打开关闭 并不在Windows任务栏显示
写完测试过得,放心使用
第2个回答 2009-12-31
你可以这样做
shell("md d:\\tp"){不用检查是否有文件夹,因为如果有这个文件夹,那么这就是条无效命令,不会有任何影响,如何没有tp文件夹,就会创建,(md 创建文件夹命令)}
shell("echo off >d:\\tp\1.txt"){原理同上}
shell("md d:\\tp"){不用检查是否有文件夹,因为如果有这个文件夹,那么这就是条无效命令,不会有任何影响,如何没有tp文件夹,就会创建,(md 创建文件夹命令)}
shell("echo off >d:\\tp\1.txt"){原理同上}
第3个回答 2009-12-31
If Dir("d:\TP", vbDirectory) = "" Then MkDir "d:\TP" '检查是否有文件夹,没有就创建
If Dir("d:\TP\1.txt") = "" Then '检查是否有1.txt,没有就创建一个
open "d:\tp\1.txt" for append as #1
close #1
end if本回答被提问者采纳
If Dir("d:\TP\1.txt") = "" Then '检查是否有1.txt,没有就创建一个
open "d:\tp\1.txt" for append as #1
close #1
end if本回答被提问者采纳
第4个回答 2009-12-31
if dir("D:\TP", vbdirectory)="" then
mkdir "D:\TP"
end if
if dir("D:\TP\1.txt", vbnormal)="" then
open "D:\TP\1.txt" for append as #1
close #1
end if
mkdir "D:\TP"
end if
if dir("D:\TP\1.txt", vbnormal)="" then
open "D:\TP\1.txt" for append as #1
close #1
end if
第5个回答 2009-12-31
只回答第二个
open "d:\tp\1.txt" for append as #1
open "d:\tp\1.txt" for append as #1