Code BATCH

Bonjour,

Actuellement j'ai un petit fichier bat qui me sauvegarde tous les jours deux fichier access avec xcopy.

Les sauvegardes vont se placer dans deux dossiers nommer comme ceci :

set jour=%date:~0,2%
set mois=%date:~3,2%
set annee=%date:~6%
set heure=%time:~0,8%

1er fichier
set a=Base-%annee%-%mois%-%jour%

2eme fichier
set aa=Source-%annee%-%mois%-%jour%

comment puis-je faire pour qu'automatiquement, le bat supprime les sauvegarde de plus de 2 mois ?

Merci d'avance,

Cordialement,

2 réponses

  1. Wo merci pour ce code, mais je n'y comprends strictement rien (et j'aime bien comprendre ^^) , je fais un petit de batch et connais pas mal le vba sur excel et access mais ca je ne comprends pas ^^

    Y aurait-il pas un moyen de gérer les dates en batch ?
    1. En batch, je trouve sa relou par contre en VBS c'est sympa.
           strComputer = "."
      
         Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2" )
         Set objFSO = CreateObject("Scripting.FileSystemObject" )
         Set objShell = CreateObject("Shell.Application" )   
        strFolderName = ("Chemin du dossier")
      
         Set colSubfolders = objWMIService.ExecQuery _
             ("Associators of {Win32_Directory.Name='" & strFolderName & "'} " _
                 & "Where AssocClass = Win32_Subdirectory " _
                     & "ResultRole = PartComponent" )
      
         arrFolderPath = Split(strFolderName, "\" )
         strNewPath = ""
         For i = 1 to Ubound(arrFolderPath)
             strNewPath = strNewPath & "\\" & arrFolderPath(i)
         Next
         strPath = strNewPath & "\\"
      
         Set colFiles = objWMIService.ExecQuery _
             ("Select * from CIM_DataFile where Path = '" & strPath & "'" )
      
         For Each objFile in colFiles
             Set objReadOnlyFile = objFSO.GetFile(objFile.Name)
              'Wscript.Echo objFile.Name & chr (10) & objReadOnlyFile.DateLastModified
          if DateDiff("d",objReadOnlyFile.DateLastModified ,Date)>nombre de jour then
      
             objFile.delete
          end if
         Next
      
         For Each objFolder in colSubfolders
             GetSubFolders strFolderName
         Next
      
         Sub GetSubFolders(strFolderName)
             Set colSubfolders2 = objWMIService.ExecQuery _
                 ("Associators of {Win32_Directory.Name='" & strFolderName & "'} " _
                     & "Where AssocClass = Win32_Subdirectory " _
                         & "ResultRole = PartComponent" )
      
             For Each objFolder2 in colSubfolders2
                 strFolderName = objFolder2.Name
                 arrFolderPath = Split(strFolderName, "\" )
                 strNewPath = ""
                 For i = 1 to Ubound(arrFolderPath)
                     strNewPath = strNewPath & "\\" & arrFolderPath(i)
                 Next
                 strPath = strNewPath & "\\"
      
                 Set colFiles = objWMIService.ExecQuery _
                     ("Select * from CIM_DataFile where Path = '" & strPath & "'" )
      
                 For Each objFile in colFiles
                 Set objReadOnlyFile = objFSO.GetFile(objFile.Name)
                 if DateDiff("d",objReadOnlyFile.DateLastModified ,Date)>)>nombre de jour then
                     'Wscript.Echo objFile.Name & chr (10) & objReadOnlyFile.DateLastModified
                     objFile.delete
      
                   end if
      
                 Next
      
                 GetSubFolders strFolderName
             Next
         End Sub
      


      les parties en gras sont a modifier.Tu peux l'excuter avec une commande dans ton batch. Il scan dossier, sous-dossier, sous sous-dossier...