Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Need help with a script

  1. #1
    Junior Member Spork's Avatar
    Join Date
    Mar 2014
    Location
    Land of 10,000 lakes
    Posts
    22
    vCash
    500
    Points
    32,395
    Bank
    0
    Total Points
    32,395
    Donate

    Question Need help with a script

    I know there are some script junkies out there that could probably rock this out with their eyes closed. But I know nothing of scripting, so this may as well all be typed in Wingdings.

    I need to modify a script we use to delete some folders. The problem being with our Citrix system is that the thinapp folders are sometimes duplicated and renamed.

    Example:
    Typically, the correct folder will read "OracleEBS". But sometimes an additional folder will be created with a .randomname, such as "OracleEBS.ABCD1234".

    We have a script currently that will automatically delete the "OracleEBS" folder, but it won't touch the folder if it's labeled "OracleEBS.ABCD1234", so we have to rename the folder to "OracleEBS" so that it can be deleted by the script.

    Here is what the script is currently:

    @echo off
    cls
    echo .
    echo ......Please wait....attempting to clear the sandbox......
    echo .
    "\\companyname.com\thinapp\oracleEBS\sleep\sleep.e xe" 10
    if exist "%appdata%\Thinstall\OracleR12" rmdir "%appdata%\Thinstall\OracleR12" /S /Q
    if exist "%appdata%\Thinstall\Oracle R12" rmdir "%appdata%\Thinstall\Oracle R12" /S /Q
    if exist "%appdata%\Thinstall\OracleEBS*" rmdir "%appdata%\Thinstall\OracleEBS" /S /Q
    echo ......Script Complete......
    echo .
    pause


    Anyone know how I can modify it to work correctly?

  2. #2
    forum fool 3fingersalute's Avatar
    Join Date
    Jan 2014
    Posts
    545
    vCash
    0
    Points
    136,427
    Bank
    0
    Total Points
    136,427
    Donate
    I'm not real great at scripts, but tested this and it worked. I'm sure somebody here can make something that looks prettier or works better but this should do it, just replace the word test with whatever your directory structures start with:

    @echo off
    cd\
    cd %appdata%
    for /d %%a in (test*) do rmdir /s /q %%a
    echo ......Script Complete......
    echo .
    pause
    "Expose yourself to your deepest fear; after that, fear has no power, and the fear of freedom shrinks and vanishes. You are free." - Jim Morrison

  3. #3
    Senior Member
    Join Date
    Jan 2014
    Posts
    725
    vCash
    0
    Points
    131,253
    Bank
    0
    Total Points
    131,253
    Donate
    I'm much better in vbscript then I am in dos scripting. If you want something in vbs I'm happy to help.

  4. #4
    Junior Member Spork's Avatar
    Join Date
    Mar 2014
    Location
    Land of 10,000 lakes
    Posts
    22
    vCash
    500
    Points
    32,395
    Bank
    0
    Total Points
    32,395
    Donate
    Quote Originally Posted by 74AD View Post
    I'm much better in vbscript then I am in dos scripting. If you want something in vbs I'm happy to help.
    If you can script something that does exactly what I need above and can be executed just by having the users double-click on a file to execute it, then go for it!

  5. #5
    Senior Member
    Join Date
    Jan 2014
    Posts
    725
    vCash
    0
    Points
    131,253
    Bank
    0
    Total Points
    131,253
    Donate
    Quote Originally Posted by Spork View Post
    If you can script something that does exactly what I need above and can be executed just by having the users double-click on a file to execute it, then go for it!
    I know the information after the extension is random but is it always the same number of characters? Just curious.

  6. #6
    Junior Member Spork's Avatar
    Join Date
    Mar 2014
    Location
    Land of 10,000 lakes
    Posts
    22
    vCash
    500
    Points
    32,395
    Bank
    0
    Total Points
    32,395
    Donate
    Quote Originally Posted by 74AD View Post
    I know the information after the extension is random but is it always the same number of characters? Just curious.
    Correct, it's a 12-digit letter/number combo that's added.

    Example: OracleEBS.ABCDEF123456

    Also, in the Thinstall folder, there are other programs listed in there as well. We only want it to delete anything labeled as "OracleEBS" or the alias "OracleEBS.ABCDEF123456"

  7. #7
    Senior Member
    Join Date
    Jan 2014
    Posts
    725
    vCash
    0
    Points
    131,253
    Bank
    0
    Total Points
    131,253
    Donate
    Code:
    StartFolder = "c:\spork"
    CleanFolder(StartFolder)
    
    Sub CleanFolder(folderspec)
        Dim fs, f, f1, fc, s
        Set fs = CreateObject("Scripting.FileSystemObject")
        Set f = fs.GetFolder(folderspec)
        Set fc = f.SubFolders
        For Each f1 in fc
     extension = instr(f1.name, ".")
    if extension = 0 then
    if f1.name = "OracleEBS" then fs.deletefolder(StartFolder & "\" & f1.name)
    else
    if left(f1.name, extension-1) = "OracleEBS" then fs.deletefolder(StartFolder & "\" & f1.name)
    end if
        Next
    End Sub
    I just did this...tested and it worked. There's no msgbox's or acknowledgements of any kind but those can be added.

    Basically you set the start folder path (your thininstall folder)
    this loops through all the sub directories one by one.
    first it checks to see it has a period in the folder name. if not, then it checks to see if it's named oracleEBS. if it is the folder is deleted.
    if has a period in the folder name, then it looks at the characters BEFORE the period and if it matches OracleEBS the folder is deleted.
    you could a a length check as well if you wanted to make sure that it only deletes oracleebs folders with a period in the name that are exactly 12 characters.....

  8. #8
    Senior Member
    Join Date
    Jan 2014
    Posts
    725
    vCash
    0
    Points
    131,253
    Bank
    0
    Total Points
    131,253
    Donate
    Here's updated code. this version throws up a little progress IE window and will only delete OracleEBS folders with a period in the name if they are exactly 22 characters in length (accounts for the added 12 character random extension)

    Code:
    StartFolder = "c:\spork"
    CleanFolder(StartFolder)
    Set objExplorer = CreateObject _
        ("InternetExplorer.Application")
    
    objExplorer.Navigate "about:blank"   
    objExplorer.ToolBar = 0
    objExplorer.StatusBar = 0
    objExplorer.Width = 400
    objExplorer.Height = 200 
    objExplorer.Visible = 1             
    
    objExplorer.Document.Title = "Clear The Sandbox"
    objExplorer.Document.Body.InnerHTML = "Hang Tight. " _
        & "Attempting to clear the sandbox."
    
    Wscript.Sleep 3000
    
    objExplorer.Document.Body.InnerHTML = "All Done!."
    
    Wscript.Sleep 1000
    objExplorer.Quit
    Sub CleanFolder(folderspec)
        Dim fs, f, f1, fc, s
        Set fs = CreateObject("Scripting.FileSystemObject")
        Set f = fs.GetFolder(folderspec)
        Set fc = f.SubFolders
        For Each f1 in fc
     extension = instr(f1.name, ".")
    if extension = 0 then
    if f1.name = "OracleEBS" then fs.deletefolder(StartFolder & "\" & f1.name)
    else
    if left(f1.name, extension-1) = "OracleEBS" and len(f1.name) = 22 then fs.deletefolder(StartFolder & "\" & f1.name)
    end if
        Next
    End Sub

  9. #9
    Junior Member Spork's Avatar
    Join Date
    Mar 2014
    Location
    Land of 10,000 lakes
    Posts
    22
    vCash
    500
    Points
    32,395
    Bank
    0
    Total Points
    32,395
    Donate
    Awesome dude! Thanks for your expertise!

  10. #10
    Senior Member
    Join Date
    Jan 2014
    Posts
    725
    vCash
    0
    Points
    131,253
    Bank
    0
    Total Points
    131,253
    Donate
    you just need to change the StartFolder variable.

    in the code I pasted, I have it set to C:\spork which was the folder I created to test the code.

Posting Permissions

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