Kaseya Community

script to remove folder

  • I"m trying to check for the presence of a folder and if it is there delete the folder. I'm not seeing the option of checking for a folder, so i'm checking for a file that is always there as well. the problem is that when trying to delete the folder via comman shell i have to put in the yes option, i don't know that switch, but then i also get the file access denied afterwards.

    script is comming up as succesful because it can load the shell command.
    any suggestions.

    the end result is i have a program that is periodically crashing, and to fix it i delete these folders. so i want to be able to delete them on a pre determined bases (every night)


    Script Name: delete folder
    Script Description: delete a folder

    IF Test File
    Parameter 1 : %TEMP%\SM_OBS_DLL\800181
    Exists Red FacedbserverDLL.dll
    THEN
    Execute Shell Command - (Continue on Fail)
    Parameter 1 : rmdir %TEMP% SM_OBS_DLL
    Parameter 2 : 1
    OS Type : 0
    ELSE
    Delete File
    Parameter 1 :
    OS Type : -1

    Legacy Forum Name: script to remove folder,
    Legacy Posted By Username: allan morris
  • Hi,

    rd /s/q foldername

    will delete it out silently.

    Perhaps you want to do a script that does:

    If True
    Execute Shell Command
    rd /s/q foldername

    Who cares if the folder exists or not. Just delete it as that command will take no time at all if the folder doesn't exist.

    Regards,
    Chris

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: chris@busy.co.nz
  • You can test for a folder by doing a Check File for C:\Windows\Temp\NUL

    NUL is an invisible file in every directory.

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: GDRBrian
  • That's a handy little trick that nul file. Thanks for that!

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: chris@busy.co.nz
  • Thank you, glad to see i was on the correct track, i just couldn't figure out how to push the commands to the shell.

    Thanks for all the help guys.

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: allan morris
  • Here's a script I created to delete a folder. I use it all the time and it works great! Hope this helps.


    IF Test File
    Parameter 1 : foldername\NUL
    Exists :
    THEN
    Execute Shell Command
    Parameter 1 : rd /s /q "foldername"
    Parameter 2 : 0
    OS Type : 0
    ELSE
    Write Script Log Entry
    Parameter 1 : The "foldername" was not found. No files were deleted.
    OS Type : 0

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: Chris Cady