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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
Dim objFSO, objDossier, objFichier
Dim sCurrentFile As String
Dim sOldFileName As String
Dim sFileName As String
Dim sLastFileName As String
Dim sVersion As String
Dim nOldNumVersion As Integer
Dim sExt As String
Dim sLastFilesVersion As String
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objDossier = objFSO.GetFolder("D:\Temporaire\Nouveau dossier")
nOldNumVersion = 0
sOldFileName = ""
sLastFilesVersion = ""
For Each objFichier In objDossier.Files
' Récupère le nom du fichier courrant
sCurrentFile = GetCurrentFileName(objFichier)
' Récupère le nom du fichier (Sans la version )
sFileName = GetFileName(sCurrentFile)
' Récupère la version (sans le 'V')
sVersion = GetVersion(sCurrentFile)
' Récupère l'extension
sExt = GetExt(sCurrentFile)
If Not (Len(sOldFileName) = 0 Or sOldFileName = sFileName) Then
If Len(sLastFilesVersion) > 0 Then
sLastFilesVersion = sLastFilesVersion + ","
End If
sLastFilesVersion = sLastFilesVersion + sOldFileName + "V" + CStr(nOldNumVersion) + sExt
nOldNumVersion = 0
sOldFileName = ""
End If
sOldFileName = sFileName
If nOldNumVersion < Val(sVersion) Then
nOldNumVersion = Val(sVersion)
End If
Next
Set objDossier = Nothing
Set objFSO = Nothing
If Len(sLastFilesVersion) > 0 Then
sLastFilesVersion = sLastFilesVersion + ","
End If
sLastFilesVersion = sLastFilesVersion + sOldFileName + "V" + CStr(nOldNumVersion) + sExt
MsgBox (sLastFilesVersion)
End Sub
Private Function GetFileName(ByVal sFileName As String) As String
GetFileName = Mid(sFileName, 1, InStr(1, sFileName, "V") - 1)
End Function
Private Function GetExt(ByVal sFileName As String) As String
GetExt = Mid(sFileName, InStr(1, sFileName, "."))
End Function
Private Function GetVersion(ByVal sFileName As String) As String
Dim nPos As Integer
Dim nPos2 As Integer
nPos = InStr(1, sFileName, "V")
nPos2 = InStr(1, sFileName, ".")
GetVersion = Mid(sFileName, nPos + 1, nPos2 - (nPos + 1))
End Function
Private Function GetCurrentFileName(ByVal sFileName As String) As String
Dim sTemp() As String
sTemp = Split(sFileName, "\")
GetCurrentFileName = sTemp(UBound(sTemp))
End Function |
Partager