Supprimer un fichier d'extension. NK2

sekmai Messages postés 18 Date d'inscription jeudi 15 avril 2010 Statut Membre Dernière intervention 13 septembre 2010 - 12 août 2010 à 19:41
sekmai Messages postés 18 Date d'inscription jeudi 15 avril 2010 Statut Membre Dernière intervention 13 septembre 2010 - 16 août 2010 à 14:44
Bonjour à tous,
j'avais éditer le script ci-dessous afin de supprimer le fichier outlook.NK2. ce fichier est le cache des contacts Outlook. mais je me suis rendu compte que le nom du fichier varie d'un systéme à un autre. c'est soit outlook.NK2 ou login_utilisateur.NK2.
je voudrais donc que vous m'aider à corriger ce srcipt afin qu'il supprime selon l'extension.NK2
Dim fso, ws, AppData, Chemin, MyFile
Set ws = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
AppData = ws.ExpandEnvironmentStrings("%AppData%")
Chemin = AppData & "\Microsoft\Outlook\*.NK2"
If (fso.FileExists(Chemin)) Then
        Set MyFile = fso.GetFile(Chemin)
        If (MyFile.datecreated < "#20/07/2010#") Then
Msgbox " Le fichier " & MyFile.name & " va être supprimer !",64,"Fichier à Supprimer"
                MyFile.Delete
               else
               Msgbox "Rien à supprimer"
        End If
Else
Msgbox "n'existe pas"
WScript.Quit
End If 
     
 

2 réponses

cs_ghuysmans99 Messages postés 3982 Date d'inscription jeudi 14 juillet 2005 Statut Membre Dernière intervention 30 juin 2013 16
13 août 2010 à 16:42
Devrait fonctionner ...
Option Explicit

Function findFile(FSO, Folder, Ext)
'Returns TRUE if the file with the `Ext` extension wasn't found in the `Folder` directory.
'Usage: FindFile(objFSO,"C:\WINDOWS","exe")

Dim FSO_Folder, FSO_File, Ext_L
Set FSO_Folder = FSO.GetFolder(Folder)
Ext_L Len(Ext) : Ext "." & LCase(Ext)
For Each FSO_File In FSO_Folder.Files
If (Len(FSO_File.Name) > Ext_L) And (LCase(Right(FSO_File.Name, Ext_L+1)) = Ext) Then
Set FindFile = FSO_File
Exit Function
End If
Next
Set FSO_Folder = Nothing
Set FindFile = Nothing
End Function



Dim FSO: Set FSO = CreateObject("Scripting.FileSystemObject")
Dim WSH: Set WSH = CreateObject("WScript.Shell")
Dim Folder, NK2
 
Folder = WSH.ExpandEnvironmentStrings("%APPDATA%") & "\Microsoft\Outlook"
Set NK2 = FindFile(FSO, Folder, "nk2")
If NK2 Is Nothing Then
MsgBox "Fichier .NK2 introuvable dans le répertoire " & Folder, vbExclamation, "Erreur"
Else
If NK2.DateCreated < "#20/07/2010#" Then
MsgBox "Le fichier " & NK2.Name & " va être supprimé !", vbInformation, "Suppression du NK2"
NK2.Delete
Else
MsgBox "Rien à supprimer.", vbInformation, "Info"
End If
Set NK2 = Nothing
End If


VB.NET is good ... VB6 is better
Utilise Réponse acceptée quand un post répond à ta question
0
sekmai Messages postés 18 Date d'inscription jeudi 15 avril 2010 Statut Membre Dernière intervention 13 septembre 2010
16 août 2010 à 14:44
voilà ce que jai fait avant que tu ne repondre à mon post. tu peux verifie STP afin de l'ameliorer si necessaire? merci

Dim fso, ws, AppData, Dossier,rep
Set ws = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
AppData = ws.ExpandEnvironmentStrings("%AppData%")
Dossier = AppData & "\Microsoft\Outlook"
Set rep = fso.GetFolder(Dossier)
effaceNK2(rep) 
function effaceNK2(rep) 
For Each AFile In rep.Files  
If UCase(FSO.GetExtensionName(AFile.Path)) = "NK2" then 
if (AFile.datecreated >= "#16/08/2010#") Then
Msgbox " Le fichier va être supprimer !",64,"Fichier à Supprimer"
AFile.Delete
ELSE 
Msgbox " RIEN à SUPPRIMER "
end if
else
WScript.Quit
end if
next 
end function 
0
Rejoignez-nous