dcsimg
Results 1 to 2 of 2
  1. #1

    Thread Starter
    New Member
    Join Date
    May 2018
    Posts
    8

    Can I amend a VBscript as I dont know if I can .

    Hi

    Im extremely new to .VBS script and rusty so please go easy on me

    I have a script that does 90% of what I want it to do. Im trying to get the script to not ask me for file name every time and just look in C:\DOWNLOADS -C:\DOWNLOADS1 -C:\DOWNLOADS2. If you cant do that individual commands OK.

    I also need the exe files that are over 7 days old after DATE CREATED only deleted and not all of them .

    YES they are .EXE files as they are 7zipped files and I have tried it and it works apart from what ive put above.

    Script below. Any ideas?


    Dim fldPath, FSO, File, Folder, filExt

    Set FSO = CreateObject("Scripting.FileSystemObject")
    fldPath = InputBox("Enter path of files?", "Directory Path")

    If Trim(fldPath) = "" Then
    MsgBox "No directory was entered.", vbOKOnly
    WScript.Quit
    Else
    If FSO.FolderExists(fldPath) Then
    ' Continue program
    Else
    MsgBox "Directory does not exist.", vbOKOnly
    WScript.Quit
    End If
    End If

    Set Folder = FSO.GetFolder(fldPath)

    For Each File In Folder.Files
    If Right(File.name, 4) = ".exe" Then
    FSO.DeleteFile(fldPath & "\" & File.name)
    End If

  2. #2
    Hyperactive Member
    Join Date
    Nov 2017
    Posts
    363

    Re: Can I amend a VBscript as I dont know if I can .

    Code:
    fldPath = InputBox("Enter path of files?", "Directory Path")
    The above line is why you are being asked for a path each time. If you don't want it to ask, that line should be removed.

    If, for example, you were to replace the line I quoted above with:

    Code:
    fldPath = "C:\DOWNLOADS\"
    that should cause the script to run silently for that one folder. It should be possible to use a loop and string concatenation to do what you want to do regarding the multiple similarly named folders (C:\DOWNLOADS1\, C:\DOWNLOADS2, etc.)

    In the case of people seeking code that takes potentially non-recoverable actions, like deleting files, I won't post functional code to assist, because I don't want to be responsible for any unintended actions that code might take on your system.

    So, my suggestion would be to read up on how to write functions, how to write For Loops, String concatenation, etc. Then, create a dummy script that simply runs a For Loop, and inside the For Loop calls a function while passing a string that is pieced together from a hard-coded string and the value of the For loop counter, and then inside the function simply display a messagebox of that passed string, and verify that everything works as expected. Once you have that then implementing the code to do what you want with files becomes somewhat trivial.

    I hope that makes sense to you. If not, then you probably shouldn't be trying to write a script that automates the deletion of files.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width