设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 1824|回复: 0
打印 上一主题 下一主题

批量修改文件名,为什么总是提示文件未找到?

[复制链接]
跳转到指定楼层
1#
发表于 2007-11-17 19:34:21 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
这个是我用来批量修改文件名的,但是总是提示文件未找到!如果将最后一行的
GetFileName = Right(FullFileName, z - 4),改为getfilename=left(fullfilename,z-4)却可以运行,高手帮我看看了!!

Sub renametxt2txt()
    Dim rc_files As Variant      ' Var for the Varient
                                    ' Holds the files that the users selects
                                    
    Dim a_FileName As String     ' Holds the name of a String
   
    Dim FoxFiles As Variant         'Holds the DBF files the user selected.
    Dim FoxFile As String           'Holds one of the DBF files from FoxFIles.
    Dim FoxFilename As String       'Name of the DBF file  ex:  Filename.dbf
    Dim WorkingPath As String       'Path of the DBF files the user selected.
   
    Dim FileCount As Long           'Holds the number of files the user selected.
    Dim WorkingFile As String       'Holds the temporary name of the DBF file being parsed.
                                    'The working file is a copy of the actual file being parsed
                                    '   with a new name. The new name is WorkingPath + TempFileName
   
    Dim b_isArray As Boolean
   
    Dim newFileName As String
   
   
    On Error GoTo ExitSub
        
    ' MsgBox ("I just wanted to say hello", vbOKOnly, "Sanity Check MsgBox", , "I think this is the content" , Context As Variant
   
   
   
   
   
    'Select Files
    rc_files = Array()
    rc_files = Application.GetOpenFileName("文本文件 (*.*), *.*", _
                            1, "Select file to ReName", "Select", True)
     
    If (UBound(rc_files) > 0) Then
        FileCount = UBound(rc_files)
        On Error GoTo ErrHandler
        ' For all the files in the list
        For Y = 1 To FileCount
            a_FileName = rc_files(Y)
         
            newFileName = GetFileName(a_FileName)
           
'           newFileName = a_FileName & "txt"
            ' Rename the files
            Name a_FileName As newFileName
        Next Y
        
       FileCount = FileCount + 1
    End If
        
ExitSub:
    Exit Sub
ErrHandler:
    MsgBox Error
    Exit Sub
End Sub
Public Function GetFileName(FullFileName As String) As String
Dim z As Integer
z = Len(FullFileName)
GetFileName = Right(FullFileName, z - 4)
End Function
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-6-6 13:00 , Processed in 0.091676 second(s), 24 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表