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

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

    VB6 编写程序时,经常遇到文件名中含有Unicode字符的文件名,常规的Name语句,Open语句,甚至Windows 中API函数都无法处理这里的文件名,因为这些文件在VB String字符串中变成了?,而问句是无法处理的,找了很多资料都没能解决这个问题,原来以为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

PrivateSub Ren_unicodeFile()

    DimFso, FsoFldr

    DimsFile, shrFile, lngFile AsString, ib AsLong

    DimsF1 As String, sF2 AsString, sPath1 AsString

          

 If1 = 1 Then

     CommonDialog1.FileName ="*.htm"

     CommonDialog1.ShowOpen

     sF1 = CommonDialog1.FileName

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

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

       

    SetFso = CreateObject("Scripting.FileSystemObject")

    SetFsoFldr = Fso.GetFolder(sPath1).Files

    ForEach sFile InFsoFldr

        lngFile = sFile.Name

        ib = InStr(lngFile, ChrW(160))

        IfLCase(sFile.shortName) Like"*.htm" And ib > 0 Then

            shrFile = sFile.ShortPath

            Name shrFileAs sF2

        EndIf

    Next

 ElseIf1 = 0 Then

    SetFso = CreateObject("Scripting.FileSystemObject")

    IfFso.FolderExists(sPath) Then

  

        ForEach sFile InFso.GetFolder(sPath).Files

            SetFsoFile = Fso.GetFile(sFile)

            shrFile = FsoFile.ShortPath

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

            I = I + 1

        Next

    EndIf

  EndIf

    SetFso = Nothing

    MsgBox"OK"

EndSub

 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值