您的位置:首页 > 编程语言 > VB

VB 用Fso函数处理带有问号的Unicode文件名

2012-12-31 19:52 435 查看

VB用Fso函数处理带有问号的Unicode文件名

VB6编写程序时,经常遇到文件名中含有Unicode字符的文件名,常规的Name语句,Open语句,甚至Windows中API函数都无法处理这里的文件名,因为这些文件在VBString字符串中变成了?,而问句是无法处理的,找了很多资料都没能解决这个问题,原来以为Fso仅能处理文本文件流,但是其目录对象、文件对象中有些方法,可以解决这一难题。
故此记录下来,以备后用。程序代码,随写随记,就没有规范化了。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
Private
Sub

Ren_unicodeFile()

Dim
Fso,FsoFldr

Dim
sFile,shrFile,lngFile
As
String
,ib
As
Long

Dim
sF1
As
String
,sF2
As
String
,sPath1
As
String


If
1=1
Then

CommonDialog1.FileName=
"*.htm"

CommonDialog1.ShowOpen

sF1=CommonDialog1.FileName

sPath1=Left(sF1,InStrRev(sF1,"\"))

sF2=
"r:\new\test.htm"


Set
Fso=CreateObject(
"Scripting.FileSystemObject"
)

Set
FsoFldr=Fso.GetFolder(sPath1).Files

For
Each

sFile
In
FsoFldr

lngFile=sFile.Name

ib=InStr(lngFile,ChrW(160))

If
LCase(sFile.shortName)
Like
"*.htm"

And
ib>0
Then

shrFile=sFile.ShortPath

NameshrFile
As

sF2

End
If

Next

ElseIf
1=0
Then

Set
Fso=CreateObject(
"Scripting.FileSystemObject"
)

If
Fso.FolderExists(sPath)
Then


For
Each

sFile
In
Fso.GetFolder(sPath).Files

Set
FsoFile=Fso.GetFile(sFile)

shrFile=FsoFile.ShortPath

NameshrFile
As

"r:\new\"&Format(I,"
0000
")&"
.txt"
'文件改名为0001.txt-

I=I+1

Next

End
If

End
If

Set
Fso=
Nothing

MsgBox
"OK"

End
Sub

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: