Il giorno lunedì 9 marzo 2015 11:06:57 UTC+1, Alfio ha scritto:
[...]
Post by AlfioPost by Maurizio Borrelliidarticolo (Duplicati non ammessi)
codarticolo (Duplicati non ammessi)
Esatto
Post by Maurizio Borrellicodarticolo.ext
(E non esistono file con lo stesso nome e diversa estensione. Ma quei file non hanno tutti la stessa estensione? Per esempio tutti .jpg. O tutti .bmp. Ecc.)
Sono tutti .jpg
Post by Maurizio Borrellicodarticolo<spazio>--<spazio>(000)<spazio>(idarticolo).ext
Ho capito giusto?
Perfetto!!
Ciao Alfio,
allora potresti fare cosi':
Option Compare Database
Option Explicit
Public Sub Test()
Const cstrPath = "D:\Archivi\Forums\icaa\Rinominare file\"
Const cstrExt = ".jpg"
Const cstrOldMask = "%cd%" & cstrExt
Const cstrNewMask = "%cd% -- (000) (%id%)" & cstrExt
Const cstrTblName = "TArticoli"
Const cstrIdName = "idarticolo"
Const cstrCdName = "codarticolo"
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim fdId As DAO.Field
Dim fdCd As DAO.Field
Dim sql As String
Dim strOldPathName As String
Dim strNewPathName As String
sql = "SELECT" _
& " T." & cstrIdName _
& ",T." & cstrCdName _
& " FROM " & cstrTblName & " AS T" _
& ";"
Set db = Application.CurrentDb
Set rs = db.OpenRecordset(sql, dbOpenForwardOnly, dbReadOnly)
With rs
If .BOF And .EOF Then
' NO RECS!
Else
Set fdId = .Fields(cstrIdName)
Set fdCd = .Fields(cstrCdName)
Do Until .EOF
strOldPathName = cstrPath _
& Replace(cstrOldMask, "%cd%", fdCd.Value)
strNewPathName = cstrPath _
& cstrNewMask
strNewPathName = Replace(strNewPathName, "%cd%", fdCd.Value)
strNewPathName = Replace(strNewPathName, "%id%", CStr(fdId.Value))
Debug.Print strOldPathName
Debug.Print strNewPathName
Debug.Print
If Len(Dir(strOldPathName)) Then
Name strOldPathName As strNewPathName
Else
Debug.Print "IL FILE NON ESISTE!"
End If
.MoveNext
Loop
End If
End With
On Error Resume Next
rs.Close
Set fdCd = Nothing
Set fdId = Nothing
Set rs = Nothing
Set db = Nothing
End Sub
--
Ciao!
Maurizio