Quantcast
Channel: VBForums - ASP, VB Script
Viewing all articles
Browse latest Browse all 686

[RESOLVED] How to move file while renaming it with incrementation if the file exists ?

$
0
0
Hi :wave:
In order to improve my script Hackoo VIRUS Cleaner.vbs

I created this code to test it before to implement it in my main script, but, i get some issues with this at line N° 46 with Error Saying "File dosen't exists"

Thank you for your help !

Code:

Option Explicit
Dim SFile,SFile1,SFile2,SFile3,SFile4,Folder,Title,Rename
Title = "Moving File to the Quarantaine Folder ..."
SFile = "E:\HackooTest\Nouveau dossier\VIRUS.vbs"
Folder = "E:\HackooTest\Quarantaine"
Rename = GetNameFile(sFile)
Call MoveFile2Quarantaine(sFile,Folder,Rename)
MsgBox "The File " & DblQuote(Rename) & " is moved to the Quarantaine Folder",VbInformation,Title
'*************************************************************************************
SFile1 = "E:\HackooTest\Nouveau dossier(2)\VIRUS.vbs"
Rename = GetNameFile(sFile1)
Call MoveFile2Quarantaine(sFile1,Folder,Rename)
MsgBox "The File " & DblQuote(Rename) & " is moved to the Quarantaine Folder",VbInformation,Title
'*************************************************************************************
SFile2 = "E:\HackooTest\Nouveau dossier(3)\VIRUS.vbs"
Rename = GetNameFile(sFile2)
Call MoveFile2Quarantaine(sFile2,Folder,Rename)
MsgBox "The File " & DblQuote(Rename) & " is moved to the Quarantaine Folder",VbInformation,Title
'*************************************************************************************
SFile3 = "E:\HackooTest\Nouveau dossier(4)\VIRUS.vbs"
Rename = GetNameFile(sFile3)
Call MoveFile2Quarantaine(sFile3,Folder,Rename)
MsgBox "The File " & DblQuote(Rename) & " is moved to the Quarantaine Folder",VbInformation,Title
'*************************************************************************************
SFile4 = "E:\HackooTest\Nouveau dossier(5)\VIRUS.vbs"
Rename = GetNameFile(sFile4)
Call MoveFile2Quarantaine(sFile4,Folder,Rename)
MsgBox "The File " & DblQuote(Rename) & " is moved to the Quarantaine Folder",VbInformation,Title
'*************************************************************************************
Sub MoveFile2Quarantaine(sFile,Folder,Rename)
        'On Error Resume Next
        Dim  FSO,Ws,Tab,i,j
        Set Ws = CreateObject("Wscript.Shell")
        Set FSO = CreateObject("Scripting.FileSystemObject")
        'Tab = Split(sFile,"\")
        'Rename = Tab(UBound(Tab))
        i = 0
        j = i + 1
        Do
                i = i + 1
                'If FSO.FolderExists(Folder) Then
                        If Not FSO.FileExists(Folder & "\" & Rename & "_Infected.txt") Then
                                FSO.GetFile(sFile).Move Folder & "\" & Rename & "_Infected.txt"
                                Exit Sub
                        ElseIf Not FSO.FileExists(Folder & "\" & Rename & "("& i &")" & "_Infected.txt") Then 'And FSO.FileExists(Folder & "\" & Rename & "_Infected.txt") Then
                                FSO.GetFile(sFile).Move Folder & "\" & Rename & "("& j &")" & "_Infected.txt"
                                Exit Sub
                        ElseIf j = i Then
                                j = j + 1
                                If Not FSO.FileExists(Folder & "\" & Rename & "("& j &")" & "_Infected.txt") Then
                                        FSO.GetFile(sFile).Move Folder & "\" & Rename & "("& j &")" & "_Infected.txt"
                                        Exit Sub
                                End if
                        End If
                'End If
        Loop Until j = i
End Sub
'**********************************************************************************************
'Fonction pour ajouter les doubles quotes dans une variable
Function DblQuote(Str)
        DblQuote = Chr(34) & Str & Chr(34)
End Function
'**********************************************************************************************
Function GetNameFile(sFile)
        Dim  Tab
        Tab = Split(sFile,"\")
        GetNameFile = Tab(UBound(Tab))
End Function


Viewing all articles
Browse latest Browse all 686

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>