I try to simplify my code using indexes but I have a problem at level
Syntax error.
[/PHP]
Code:
MkDir (strPathNl) & newNameA & "\" & newNameA&i
Syntax error.
Code:
Sub RenommerDossier()
'Pr?alable: v?rifier si les r?f?rence n?cessaires au FileSystemObject sont activ?es.
Dim objFSO As FileSystemObject
Dim mySource As Object
Dim Folder As Variant
Dim newName As String
Dim strPathNl As String
Dim strSql As String
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim i As Long
toPath = "C:\Pers1"
newNameA = "A. Pieces officielles"
newNameA1 = "1. P1"
newNameA2 = "2. Werfbundel"
newNameA3 = "3. Overige"
newNameA4 = "4. Contracten"
newNameA5 = "5. Wijzigingen"
newNameB = "B. Promotions"
Set dbs = CurrentDb
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder("C:\Pers1\")
strSql = "SELECT Matr, NomName, NomName,NomNameMatr, Languagecode FROM DEC WHERE Matr = 3500"
Set rst = dbs.OpenRecordset(strSql, dbOpenSnapshot, dbFailOnError)
strPathNl = toPath & "\" & rst!NomName & "\" '. Pieces officielles\"
If Dir(strPathNl, vbDirectory) = "" Then
MsgBox "Le r?pertoire n'existe pas"
MkDir (strPathNl)
MkDir (strPathNl) & newNameA
For i = 1 To 5
i = i + 1
MkDir (strPathNl) & newNameA & "\" & newNameA&i & "\"
' MkDir (strPathNl) & newNameA & "\" & newNameA2 & "\"
' MkDir (strPathNl) & newNameA & "\" & newNameA3 & "\"
' MkDir (strPathNl) & newNameA & "\" & newNameA4 & "\"
' MkDir (strPathNl) & newNameA & "\" & newNameA5 & "\"
Next
MkDir (strPathNl) & newNameB
Else
MsgBox "Le r?pertoire existe"
End If
Set objFSO = New FileSystemObject
Set mySource = objFSO.GetFolder(strPathNl)
For Each Folder In mySource.SubFolders
If InStr(1, Folder.Name, "A.") > 0 Then
If Not Folder.Name Like newName Then
Folder.Name = newName
'v?rifier si l'on ne traite pas le m?me r?pertoire plus d'une fois !!
If Folder.Name <> newName Then Folder.Name = newName
End If
End If
Next Folder
Set objFSO = Nothing
Set mySource = Nothing
End Sub