none
Microsoft VBScript runtime error: permission denied

    Question

  • Hi Guys,

    I desperately need assistance i'm using this copying FSO script on all my windows 2000 application servers and it's working on all except 1 and can't seem troubleshoot what the problem could be. I'm getting a "Permission Denied error". Can you please assist me urgently as i'm running out space and need to copy these files first before deleting it?

    '
    ' Script to delete files older than a given number of days.
    '
    ' WARNING: Files deleted with this program could not be recovered. They don't even get to Recycle Bin.
    '          Use at your own risk.
    '
    ' (C) Copyright, 2002. Ferran Foz. Barcelona, Spain. ferran@ostres.com
    '
    ' You may copy and distribute without changing the copyright notice.
    '
    '
    Set StdOut = WScript.StdOut
    Set fso = CreateObject("Scripting.FileSystemObject")

    Main

    Sub Main()
     '
     ' DropOldFiles
     ' folderspec    - Folder where you want to delete files
     ' logfile       - File where logfile will be generated.
     ' days       - Number of days to keep files.
     ' origfolder    - Folder populated by "ftrickle"
     ' storagefolder - Temporary holding folder to store data longer (drive c: running out of space)
     ' copydays      - Number of days after which files to be moved to drive D:
     ' d_path       - Actuall folder where the copied data is to be kept
     '
            LogOpen("C:\BackupDELLOG.TXT")
     Call CopyOldFiles("C:\Program Files\Matra Systems\Store","\\ntcsql16\MatraArchive\ntsispeapp02\Store","c:\BackupDelLog.TXT", 10)
            '
     '       Call DropOldFiles("\\ntcsql16\MatraArchive\ntsispeapp02\Store","c:\BackupDelLog.TXT", 100)
            '
            LogClose
    End Sub 

    ' ***************************************************************************************** 

    Sub CopyOldFiles(origfolder, storagefolder, logfile, copydays)
      Dim f,f1,s,fi, cnt, tot, path, d_path 
          
     
      cnt = 0
      tot = 0
      path = ""
      d_path = ""
     
      Set f = fso.GetFolder(origfolder)
      logwrite f & " <f> "
      Set fc = f.Files
      For Each f1 in fc
            path = f.Path
            path = path + "\"
            path = path + f1.name
      'logwrite path & " <1> "
      'logwrite f.name & " <f.name> "  
            WScript.Echo("File: " + path)
     If DateDiff ("d",f1.DateLastModified, Now ) > copydays Then
      LogWrite path & " DateLastModified:" & f1.DateLastModified & " DaysOld:" & DateDiff ("d",f1.DateLastModified, Now )               
       '  check if path exists with current folder (eg. store_452), if not, create it
       
      d_path = storagefolder + "\" + f.name    ' f.name will be the actuall folder with the tlogs (eg. store_452)
      'logwrite d_path & " <d_path> "
          'If (fso.FolderExists(d_path)) Then ' This whole IF commented out, also works
                  'logwrite d_path & " exists."
          'Else
                 'logwrite d_path & " doesn't exist."
           'fso.CreateFolder(d_path)
          'End If

         If not (fso.FolderExists(d_path)) Then  ' Same as above statement
        fso.CreateFolder(d_path)
      End If

      d_path = d_path + "\"     ' Have to append the "\" else next statement doesn't work
      '      fso.MoveFile path, d_path    ' Used when MOVING files
      fso.CopyFile path, d_path

      cnt = cnt + 1
     End If
     tot = tot + 1
      Next

      For Each subfolder in f.subfolders
          WScript.Echo("Subfolder: " + subfolder.Path)
          Call CopyOldFiles(subfolder.Path, storagefolder, logfile, copydays) 
      Next

      LogWrite "--------------------------------------------------------------"
      LogWrite " Processed " & tot & " file(s). Copied " & cnt & " file(s)."
      LogWrite "--------------------------------------------------------------"

    End Sub

    ' ***************************************************************************************** 

    Sub DropOldFiles(folderspec, logfile, days)
      Dim f,f1,s,fi, cnt, tot, path
     
      cnt = 0
      tot = 0
      path = ""
     
      Set f = fso.GetFolder(folderspec)
      Set fc = f.Files
      For Each f1 in fc
            path = f.Path
      logwrite path & " <2nd sub> "
            path = path + "\"
            path = path + f1.name
            WScript.Echo("File: " + path)
     If DateDiff ("d",f1.DateLastModified, Now ) > days Then
      LogWrite path & " DateLastModified:" & f1.DateLastModified & " DaysOld:" & DateDiff ("d",f1.DateLastModified, Now )               
        fso.DeleteFile (path)
      cnt = cnt + 1
     End If
     tot = tot + 1
      Next
      For Each subfolder in f.subfolders
          WScript.Echo("Subfolder: " + subfolder.Path)
          Call DropOldFiles(subfolder.Path, logfile, days) 
      Next
      LogWrite "--------------------------------------------------------------"
      LogWrite " Processed " & tot & " file(s). Deleted " & cnt & " file(s)."
      LogWrite "--------------------------------------------------------------"
     
    End Sub 
     

    ' ***************************************************************************************** 

    '
    ' Write to the Logfile
    '

    Dim LogFile

    Sub LogWrite (Text)
     LogFile.WriteLine "[" & Now & "] " & Text
    End Sub 

    Sub LogClose ()
     LogFile.Close
     Set Logfile=nothing
    End Sub 

    Sub LogOpen (LogPath)
      Dim fso, f1
      Const ForAppend = 8
     Set fso = CreateObject("Scripting.FileSystemObject")
     Set LogFile = fso.OpenTextFile(LogPath, ForAppend, True)
     Set fso = nothing
    End Sub




    • Moved by Jeff Shan Monday, November 30, 2009 3:05 AM vbs question (From:Visual Basic General)
    Thursday, November 26, 2009 10:16 AM

Answers