Vb的问题 汗 T_T
来源:百度知道 编辑:UC知道 时间:2024/05/27 10:00:28
Private Sub cmdCreat_Click()
Dim x As String
Open App.path & "\save.txt" For Input As #1
While Not EOF(1)
Line Input #1, x
If InStr(x, ".*") = 0 Then
Open App.path & "\path.txt" For Output As #2
Print #2, x
'MkDir App.Path & "\新建文件")
Close #2
Else
MsgBox "无法创建"
Close #2
End If
Wend
Close #1
End Sub
我这段代码有什麼问题?
为什麼比如save.txt里面是这样的内容
C:\Documents and Settings\f2908233\桌面\目录\MSSCCPRJ.SCC
C:\Documents and Settings\f2908233\桌面\目录\Project1.vbp
C:\Documents and Settings\f2908233\桌面\目录\Project1.vbw
C:\Documents and Settings\f2908233\桌面\目录\实验.vbp
C:\Documents and Settings\f2908233\桌面\目录\新资料夹
C:&
Dim x As String
Open App.path & "\save.txt" For Input As #1
While Not EOF(1)
Line Input #1, x
If InStr(x, ".*") = 0 Then
Open App.path & "\path.txt" For Output As #2
Print #2, x
'MkDir App.Path & "\新建文件")
Close #2
Else
MsgBox "无法创建"
Close #2
End If
Wend
Close #1
End Sub
我这段代码有什麼问题?
为什麼比如save.txt里面是这样的内容
C:\Documents and Settings\f2908233\桌面\目录\MSSCCPRJ.SCC
C:\Documents and Settings\f2908233\桌面\目录\Project1.vbp
C:\Documents and Settings\f2908233\桌面\目录\Project1.vbw
C:\Documents and Settings\f2908233\桌面\目录\实验.vbp
C:\Documents and Settings\f2908233\桌面\目录\新资料夹
C:&
搞完了!
Private Sub cmdCreat_Click()
Dim x As String, a As String 'a是save.txt中所有文件夹的路径
Open App.Path & "\save.txt" For Input As #1
While Not EOF(1)
Line Input #1, x
If InStr(x, ".") = 0 Then
a = a & x & vbCrLf
MkDir x '注意mkdir只有在父目录存在时才能创建一个子目录
Print x
Else
Print "无法创建"
End If
Wend
Close #1
Open App.Path & "\path.txt" For Output As #2
Print #2, a
Close #2
End Sub
如果按你原来的写法,打开文件的方式必须是append,否则会将原本的内容覆盖掉~~~成功后追点分~~~
要连续在一个文件中写入数据,不要重复打开多次,每次打开写入关闭都会清除原有的内容,因此path.txt里面只有最后写入的数据,可以修改为:
Private Sub cmdCreat_Click()
Dim x As String
Open App.path & "\save.txt" For Input As #1
Open App.path & "\path.txt" For Output As #2
While Not EOF(1)
Line Input #1, x
If InStr(x, ".*") = 0 Then P