1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Help with excluding a filename

Discussion in 'Software Development' started by ricebubbles, Feb 17, 2013.

Thread Status:
Not open for further replies.
Advertisement
  1. ricebubbles

    ricebubbles Thread Starter

    Joined:
    Feb 17, 2013
    Messages:
    2
    Hey Guys,

    Am hoping you can help with the following:

    I am having trouble with the following part of a purge script (in red) that I am creating:

    1) Obtain a list of FOLDERS whose 'DateLastModified' attribute is older than 28 days Output to an Array.
    2) For each FOLDER listed in the Array delete folder with the exception of a folder with a specified name.

    The issue I am having is that one of the folders passed to the array is hidden, protected etc and I do not want the delete function to be called for that folder as it causes an error and stops the entire script from completing. I am a novice at this so would appreciate your expert advice and help on this.

    '--------Delete subfolders in Root > 28 days old
    BasePath = "C:\Temp"
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set f = fso.GetFolder(BasePath)
    Set sf = f.SubFolders
    For Each f1 in sf
    CalcResult = DateDiff("d",f1.DateLastModified,Now)
    if CalcResult > 28 then
    ReDim preserve fNameArray(i)
    fNameArray(i) = f1.Name
    i = i + 1
    end if
    Next
    For Each fName in fNameArray
    fso.DeleteFolder(BasePath & "\" & fName), TRUE
    Next
     
  2. draceplace

    draceplace

    Joined:
    Jun 8, 2001
    Messages:
    2,583
    Hey RiceBubble welcome to TSG!

    Something like this will help skip records/folders in your loop.
    The code below allowed me to skip all the "Form" folders:

    strFullPath = FSO.GetAbsolutePathName(objFile)
    strFileNameA = objFile.Name

    If instr(strFullPath,"\Forms\") > 0 Then 'Skip System File
    FormSkipCnt = FormSkipCnt + 1
    Else
     
  3. ricebubbles

    ricebubbles Thread Starter

    Joined:
    Feb 17, 2013
    Messages:
    2
    Hey DracePlace,

    Thanks for the prompt reply. I have taken your example and modified my script and voila it works. Here is the code that I used to get the desired results.


    For Each fName in fNameArray
    ' wscript.echo fName
    If instr(fName,"DfsrPrivate") > 0 Then 'Skip System File
    FormSkipCnt = FormSkipCnt +1
    Else
    fso.DeleteFolder(BasePath & "\" & fName), TRUE
    end if
    Next

    This has now allowed me to automate housekeeping on a dfs share that we have enabled.

    Thanks for your help. You're a lifesaver
     
  4. draceplace

    draceplace

    Joined:
    Jun 8, 2001
    Messages:
    2,583
    Your welcome, RiceBubbles. Excellant job adapting the code! Please mark this thread as solved (button at the top an bottom) when you get a chance.
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1089966

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice