更改具有不同扩展名的2个不同文件的一个文件名

时间:2015-12-11 15:37:37

标签: file

我有2个文件名,其中一个是我要从中选择名称的主人来更改第二个文件。 File1 = Research.doc File2 = Laboratory.xls

在这种情况下,文件1是领导者,所以我想选择该文件的名称并为file2更改它,因此此操作的结果应为

File1 = Reserach.doc<<<< ===保持名称无变化只是为了取名 File2 = Research.xls<< == file 2更改名称,如文件1,并将相同的扩展名仅保留为文件名。

感谢提前输入

代码:

Option Explicit 
Dim strPath
Dim FSO
Dim FLD
Dim fil
Dim strOldName1
Dim strOldName2
Dim strNewName1
Dim strNewName2
Dim strFileParts
Dim strAccount1
Dim strAccount2
Dim intAccount strPath = "C:\JPMSMB15"

Set FSO = CreateObject("Scripting.FileSystemObject")
Set FLD = FSO.GetFolder(strPath)

For Each fil in FLD.Files
    strOldName1 = fil.Path
    strOldName2 = fil.Path

    If InStr(strOldName1, "") > 1 Then
        intAccount = intAccount + 0
        strAccount1 = CStr(intAccount)
        strAccount1 = Right(strAccount, 3)
        strAccount2 = CStr(intAccount)
        strAccount2 = Right(strAccount, 3)
        strFileParts = Split(strOldName1, "")
        strNewName1 = strFileParts(0) & strAccount & ".xls"
        strNewName2 = strFileParts(0) & StrAccount & ".doc"
        FSO.MoveFile strNewName1, strNewName2 
    End If
Next

0 个答案:

没有答案