Message 1 of 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Taking inspiration from various forums, I ended up writing this:
'DATI DI PARTENZA NOME = ThisDoc.FileName(False) ' ESTRAE NOME DOCUMENTO PERCORSOCOM = "\\percorso\Disegni\" 'PERCORSO INIZIALE DA VARIARE IN CASO DI NUOVA DESTINAZIONE PERCORSOFILE = PERCORSOCOM & NOME 'PERCORSO COMPLETO DI CARTELLA CON CODICE ESTENSIONEPDF = ".pdf" 'ESTENSIONEDXF = ".dxf" ESTENSIONEDWFX = ".dwfx" PERCORSOPDF = PERCORSOFILE & "\" & "PDF\" 'PERCORSO COMPLETO PER FILE PDF 'PERCORSODXF = PERCORSOFILE & "\" & "DXF\" 'PERCORSO COMPLETO PER FILE DXf PERCORSODWFX = PERCORSOFILE & "\" & "DWFX\" 'PERCORSO COMPLETO PER FILE DXf NewFileNameAndExtensionPDF = PERCORSOPDF & "\" & NOME & ESTENSIONEPDF 'PERCORSO E NOME FILE COMPLETO PER FILE PDF 'NewFileNameAndExtensionDXF = PERCORSODXF & "\" & NOME & ESTENSIONEDXF 'PERCORSO E NOME FILE COMPLETO PER FILE DXF NewFileNameAndExtensionDWFX = PERCORSODWFX & "\" & NOME & ESTENSIONEDWFX PERCORSOPDFOLD = PERCORSOPDF & "OLD\" ' PERCORSO PER VECCHI FILE PDF 'PERCORSODXFOLD = PERCORSODXF & "OLD\" ' PERCORSO PER VECCHI FILE DXF PERCORSODWFXOLD = PERCORSODWFX & "OLD\" 'CREA CARTELLE SE NON PRSENETI PDF Dim oDesiredFolder1 As String = PERCORSOPDF ' ASSEGNA VARIABILE CARTELLA PDF If Not System.IO.Directory.Exists(oDesiredFolder1) Then ' SE NON ESISTE LA CARTELLA System.IO.Directory.CreateDirectory(oDesiredFolder1) ' CREA LA CARTELLA End If 'CREA CARTELLE SE NON PRSENETI DXF 'Dim oDesiredFolder2 As String = PERCORSODXF ' ASSEGNA VARIABILE CARTELLA DXF 'If Not System.IO.Directory.Exists(oDesiredFolder2) Then ' SE NON ESISTE LA CARTELLA ' System.IO.Directory.CreateDirectory(oDesiredFolder2) ' CREA LA CARTELLA 'End If 'CREA CARTELLE SE NON PRSENETI DWFX Dim oDesiredFolder5 As String = PERCORSODWFX ' ASSEGNA VARIABILE CARTELLA DXF If Not System.IO.Directory.Exists(oDesiredFolder5) Then ' SE NON ESISTE LA CARTELLA System.IO.Directory.CreateDirectory(oDesiredFolder5) ' CREA LA CARTELLA End If 'VERIFICA SE ESISTE GIà UN FILE/CARTELLA PDF Dim currentTime As String currentTime = Now().ToString("yyyy-MM-dd_HH_mm") If System.IO.File.Exists(NewFileNameAndExtensionPDF) = True Then ' SE LA CARTELLA ESISTE GIà Dim oDesiredFolder3 As String = PERCORSOPDFOLD ' SE NON ESISTE GIA CARTELLA OLD If Not System.IO.Directory.Exists(oDesiredFolder3) Then System.IO.Directory.CreateDirectory(oDesiredFolder3)' CREA CARTELLA OLD End If Dim source As String = NewFileNameAndExtensionPDF Dim destination As String = PERCORSOPDFOLD & NOME & "_OLD_" & currentTime & ESTENSIONEPDF System.IO.File.Copy(source,destination) End If 'VERIFICA SE ESISTE GIà UN FILE/CARTELLA DXF 'If System.IO.File.Exists(NewFileNameAndExtensionDXF) = True Then ' SE LA CARTELLA ESISTE GIà ' Dim oDesiredFolder4 As String = PERCORSODXFOLD ' SE NON ESISTE GIA CARTELLA OLD ' If Not System.IO.Directory.Exists(oDesiredFolder4) Then ' System.IO.Directory.CreateDirectory(oDesiredFolder4)' CREA CARTELLA OLD ' End If ' Dim source As String = NewFileNameAndExtensionDXF ' Dim destination As String = PERCORSODXFOLD & NOME & "_OLD_" & currentTime & ESTENSIONEDXF ' System.IO.File.Copy(source,destination) 'End If 'VERIFICA SE ESISTE GIà UN FILE/CARTELLA DWFX If System.IO.File.Exists(NewFileNameAndExtensionDWFX) = True Then ' SE LA CARTELLA ESISTE GIà Dim oDesiredFolder6 As String = PERCORSODWFXOLD ' SE NON ESISTE GIA CARTELLA OLD If Not System.IO.Directory.Exists(oDesiredFolder6) Then System.IO.Directory.CreateDirectory(oDesiredFolder6)' CREA CARTELLA OLD End If Dim source As String = NewFileNameAndExtensionDWFX Dim destination As String = PERCORSODWFXOLD & NOME & "_OLD_" & currentTime & ESTENSIONEDWFX System.IO.File.Copy(source,destination) End If 'SALVATAGGIO ThisDoc.Document.SaveAs(NewFileNameAndExtensionPDF, True) 'ThisDoc.Document.SaveAs(NewFileNameAndExtensionDXF, True) ThisDoc.Document.SaveAs(NewFileNameAndExtensionDWFX, True)
However, after using it, I noticed something. If I try to save the PDF within the same minute, it gives me some problems. Additionally, the idea of adding the time in addition to the date is a convenient solution I chose because I didn't have any other ideas.
How could I modify my code to make it check if the "old" folder exists, and if it does, to check its contents and save the various files as "filename_date + sequential number"?
Thank you.
Solved! Go to Solution.