关于取字符串创建路径的问题。
从ini文件中取得全路径的字符串,在程序中创建。如果创建不成功,取得字符串中的文件名(如果字符串中包括的话,否则用缺省的文件名),在当前路径下创建。
我现在的处理方法是
用api ---MakeSureDirectoryPathExists 创建。
If MakeSureDirectoryPathExists(rstrErrLogFile) <> 1 Then
If strFileName = "" Then
strFileName = vstrDefaultFileName
End If
If Right(App.Path, 1) = "\" Then
rstrErrLogFile = App.Path & strFileName
Else
rstrErrLogFile = App.Path & "\" & strFileName
End IF
END IF
如何判断rstrErrLogFile是一个路径,而不是一个普通的字符串,如“1432340”?
因为如果不是一个路径字符串的话,MakeSureDirectoryPathExists的返回值也是1?
或者各位有没有更好的解决方法~~~~~~~~~
多谢了~~~~
问题点数:50、回复次数:7Top
1 楼mousie(浩子 〖www.xygu.com〗)回复于 2002-11-23 18:03:00 得分 15
换一个解决方法行不行,做一个模板文件,要生成文件时用FileCopy复制过去。Top
2 楼cicirain(因为是女子)回复于 2002-11-24 15:13:23 得分 0
那天走的急,问题可能没有说清楚。
我的问题主要是如何Check--rstrErrLogFile 是一个路径字符串。
现在问题已经解决了。
我增加了一个检查函数,来Check这个字符串是否是一个路径字符串。
不过VB中是否有现成的函数可以直接Check一个字符串是路径字符串类似
IsDiretory()的函数?Top
3 楼ipman(.NET)回复于 2002-11-24 15:33:17 得分 35
public function IsDiretory(byval sPath as string) as Boolean
On error resume next
ret=dir(rstrErrLogFile,vbDirectory)
if ret="" then
mkdir rstrErrLogFile
end if
if err.number=0 then 'no error
IsDiretory=True 'is a dir
else
IsDiretory=False 'not a dir
end if
end ifTop
4 楼ipman(.NET)回复于 2002-11-24 15:34:37 得分 0
错了,
public function IsDiretory(byval sPath as string) as Boolean
On error resume next
ret=dir(sPath,vbDirectory)
if ret="" then
mkdir sPath
end if
if err.number=0 then 'no error
IsDiretory=True 'is a dir
else
IsDiretory=False 'not a dir
end if
end FunctionTop
5 楼cicirain(因为是女子)回复于 2002-11-25 15:54:13 得分 0
dir 这个函数,只能检查路径字符串,不能包括文件名。
mkdir 这个函数,只能一级一级的创建路径,不可以一次创建多级文件夹。
所以………………Top
6 楼cicirain(因为是女子)回复于 2002-11-28 11:31:36 得分 0
还是没有结论~~~
:(
:'(
算啦~~
结帖~~Top




