Results 1 to 9 of 9

Thread: Script help

  1. #1
    Frankthetank1's Avatar Über User BT Rep: +25BT Rep +25BT Rep +25BT Rep +25BT Rep +25
    Join Date
    Sep 2006
    Location
    Boston
    Age
    46
    Posts
    787
    I need help creating a script for my work. Right now I have this script called move scan files.bat and I have it schedled to work at 5 pm every day.* Here is the script
    *
    @echo off
    copy "Y:\Scanned\*.*" "Y:\scanned1\"
    End
    *
    I want to create a new script that will delete files that are older then 7 days in that folder called scanned1.
    “Just because you’re miserable doesn’t mean you can’t enjoy your life.”

    DO NOT RANDOMLY PM ME ASKING FOR INVITES!

  2. Internet, Programming and Graphics   -   #2
    "I just remembered something that happened a long time ago."

  3. Internet, Programming and Graphics   -   #3
    Frankthetank1's Avatar Über User BT Rep: +25BT Rep +25BT Rep +25BT Rep +25BT Rep +25
    Join Date
    Sep 2006
    Location
    Boston
    Age
    46
    Posts
    787
    I tried it with and with out the first and last lines still get a windows compilation error. Just save it as a VBS file and run it to see if it works right? I guess, I don’t get run this in command prompt…. How?
    *
    'copy from here
    *** Function DeleteOlderFiles(Y:\Old Scanned Doc's)
    ****** Dim fso, f, f1, fc, n, ThresholdDate
    ****** Set fso = CreateObject("Scripting.FileSystemObject")
    ****** Set f = fso.GetFolder(Y:\Old Scanned Doc's)
    ****** Set fc = f.Files
    ****** Set objArgs = WScript.Arguments
    ****** n = 0
    ****** If objArgs.Count=0 Then
    ********** howmuchdaysinpast = 0
    ****** Else
    ********** howmuchdaysinpast = -objArgs(0)
    ****** End If
    ****** ThresholdDate = DateAdd("d", howmuchdaysinpast, Date)**
    ****** For Each f1 in fc
    **** If f1.DateLastModified<ThresholdDate Then
    ******* Wscript.StdOut.WriteLine f1
    ******* f1.Delete
    ******* n = n + 1***
    **** End If
    ****** Next
    ****** Wscript.StdOut.WriteLine "Deleted " & n & " file(s)."
    *** End Function
    *
    *** If Not WScript.FullName = WScript.Path & "\cscript.exe" Then
    ***** WScript.Echo "USAGE ONLY IN COMMAND PROMPT: cscript DelOldFiles.vbs 15" & vbCrLf & "15 means to delete files older than 15 days in past."
    ***** WScript.Quit 0**
    *** End If
    *
    *** DeleteOlderFiles(".")
    'to here
    *
    “Just because you’re miserable doesn’t mean you can’t enjoy your life.”

    DO NOT RANDOMLY PM ME ASKING FOR INVITES!

  4. Internet, Programming and Graphics   -   #4
    tesco's Avatar woowoo
    Join Date
    Aug 2003
    Location
    Canadia
    Posts
    21,669
    First of all, might be stupid of me to say, but don't copy the "'copy from here" or the "'to here".
    Second, when he says "USAGE ONLY IN COMMAND PROMPT: cscript DelOldFiles.vbs 15", do it like this:
    start -> run -> type "CMD" -> click OK -> then type "cscript DelOldFiles.vbs 15".
    You might need to add the path to the file to that line.

    edit: Just noticed you buggered up the code, here use this:

    Code:
    Function DeleteOlderFiles(whichfolder)
           Dim fso, f, f1, fc, n, ThresholdDate
           Set fso = CreateObject("Scripting.FileSystemObject")
           Set f = fso.GetFolder(whichfolder)
           Set fc = f.Files
           Set objArgs = WScript.Arguments
           n = 0
           If objArgs.Count=0 Then
               howmuchdaysinpast = 0
           Else
               howmuchdaysinpast = -objArgs(0)
           End If
           ThresholdDate = DateAdd("d", howmuchdaysinpast, Date)   
           For Each f1 in fc
         If f1.DateLastModified<ThresholdDate Then
            Wscript.StdOut.WriteLine f1
            f1.Delete
            n = n + 1    
         End If
           Next
           Wscript.StdOut.WriteLine "Deleted " & n & " file(s)."
        End Function
    
        If Not WScript.FullName = WScript.Path & "\cscript.exe" Then
          WScript.Echo "USAGE ONLY IN COMMAND PROMPT: cscript DelOldFiles.vbs 15" & vbCrLf & "15 means to delete files older than 15 days in past."
          WScript.Quit 0   
        End If
    
        DeleteOlderFiles(".")
    Edit the very LAST line that says "DeleteOlderFiles(".")", replace the dot(.) with the folder name.

  5. Internet, Programming and Graphics   -   #5
    Frankthetank1's Avatar Über User BT Rep: +25BT Rep +25BT Rep +25BT Rep +25BT Rep +25
    Join Date
    Sep 2006
    Location
    Boston
    Age
    46
    Posts
    787
    yeah i am a noob when it comes to scripts I will try this Tuesday.

    If this works i might try a script to do my timesheet at work so i wont even have to show up
    Last edited by Frankthetank1; 04-15-2011 at 11:22 PM.
    “Just because you’re miserable doesn’t mean you can’t enjoy your life.”

    DO NOT RANDOMLY PM ME ASKING FOR INVITES!

  6. Internet, Programming and Graphics   -   #6
    Poster BT Rep: +1
    Join Date
    Apr 2011
    Posts
    182
    If you'd like I can patch you something up in C, although it might be overkill since this can easily be achieved with batch.

  7. Internet, Programming and Graphics   -   #7
    Frankthetank1's Avatar Über User BT Rep: +25BT Rep +25BT Rep +25BT Rep +25BT Rep +25
    Join Date
    Sep 2006
    Location
    Boston
    Age
    46
    Posts
    787
    it works well but i need to figure out how to run it in a scheduled task. i think i can figure it out though...I just need to put cscript in front of the name of the vbscript and save in a cmd file
    “Just because you’re miserable doesn’t mean you can’t enjoy your life.”

    DO NOT RANDOMLY PM ME ASKING FOR INVITES!

  8. Internet, Programming and Graphics   -   #8
    The association for VBS files in the registry should look like this:
    Code:
    "%SystemRoot%\System32\WScript.exe" "%1" %*
    Just replace %1 with the full path to your file (keep the quotes) and use that.
    "I just remembered something that happened a long time ago."

  9. Internet, Programming and Graphics   -   #9
    Poster BT Rep: +1
    Join Date
    Apr 2011
    Posts
    182
    Quote Originally Posted by Frankthetank1 View Post
    it works well but i need to figure out how to run it in a scheduled task. i think i can figure it out though...I just need to put cscript in front of the name of the vbscript and save in a cmd file
    If you are on Windows then try running taskschd.msc and setting it up there.

Bookmarks

Posting Permissions

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