vb如何建立文件夹并保存文件

请教一下:在form1中一个text控件,输入一段字符作为一个文件夹的名字,然后,在form2中打开这个文件夹,并将一个txt文件保存进这个文件夹,如何处理?这样的形式:... 请教一下:在form1中一个text控件,输入一段字符作为一个文件夹的名字,然后,在form2中打开这个文件夹,并将一个txt文件保存进这个文件夹,如何处理?
这样的形式:d:\ text1.text \123.txt 不知道text1中的字符怎么转化为文件名,然后后面如何打开?每次启动程序,文件夹名都要重新命名
请赐教
展开
 我来答 举报
lanniao007
2011-09-06 · TA获得超过1012个赞
知道小有建树答主
回答量:1489
采纳率:40%
帮助的人:479万
展开全部
Form1的文件名确保输入正确.你输入多级目录或者单级目录都可以。下面代码可以参照。参数就传递你Text1.text。
Public Function CreateDir(path As String) As Boolean
Static start, pos As Integer
Static directory As String
Static result As Boolean
result = True

' initialize the error trap
On Error GoTo errCreation

' if null string why bother....
If path = "" Then Err.Raise vbObjectError + 1

' start will always be null
' the first time through
If start = Empty Then
start = 1
Else
start = pos + 1
End If

' find "\" if the char exists
pos = InStr(start, path, Chr$(92))

If (pos <> 0) Then
' not at the last directory in the path string...
directory = directory + Mid$(path, start, pos - start) + Chr$(92)
If InStr(1, Mid$(path, start, pos - start), Chr$(58)) = 0 And Dir(directory, vbDirectory) = "" Then
MkDir Mid$(directory, 1, Len(directory) - 1)
End If
' call itself
result = CreateDir(path)
ElseIf (pos = 0) Then
' the last directory or the only in the path string
directory = directory + Mid$(path, start, Len(path) - start + 1)
MkDir Mid$(directory, 1, Len(directory))
directory = ""
End If

' success return true
CreateDir = result

Exit Function

' if it gets here, an exception was thrown
' propogate the error to the calling function
errCreation:
Err.Clear
result = False
CreateDir = result

End Function
至于打开该文件夹。你可以用VB中的
Shell "explorer " & FILENAME, vbNormalNoFocus
FILENAME是文件夹或者文件名都可以。
每次启动程序,文件夹名都要重新命名,下面代码参照:
Dim i As Integer
i = 1
Set fs = CreateObject("scripting.filesystemobject")
Set fd = fs.GetFolder("d:\test")
fd.Name = "pic"
或者
Name "OldPathname" As "NewPathname" 也可以
只能给你一个实现的大概
百度网友6e36e31
2011-09-06 · TA获得超过145个赞
知道小有建树答主
回答量:280
采纳率:0%
帮助的人:164万
展开全部
vb 提供的原始方法一般不推荐使用,
你可以用“filesystemobject”组件
参考
http://baike.baidu.com/view/347454.htm
抢首赞 已赞过 已踩过<
你对这个回答的评价是?
评论 举报 收起
5485277
2011-09-06
知道答主
回答量:2
采纳率:0%
帮助的人:3457
展开全部
额!~~~
抢首赞 已赞过 已踩过<
你对这个回答的评价是?
评论 举报 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式