Kaseya Community

Delete File Script with Kaseya

  • I am trying to replace some of the old "Bat" files that we use to delete, copy and update data files and I was wondering if the Keseya script command "delete file" allows me to delete an entire directory structure or is this limited to ONE file at a a time. Any suggestions?

    Gerard

    Legacy Forum Name: Delete File Script with Kaseya,
    Legacy Posted By Username: glouise
  • glouise
    I am trying to replace some of the old "Bat" files that we use to delete, copy and update data files and I was wondering if the Keseya script command "delete file" allows me to delete an entire directory structure or is this limited to ONE file at a a time. Any suggestions?

    Gerard


    Its very easy to create a script that does what you want. Do an execute shell command. del c:\mypath\*.* /s

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: far182
  • Thanks, I did not see the "shell" option, I know how to do this now. Great.
    Thanks again

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: glouise
  • far182
    Its very easy to create a script that does what you want. Do an execute shell command. del c:\mypath\*.* /s


    The only problem with that command is that it does not delete subfolders within "mypath" if you want to remove an entire directory with subfolders. It will delete the files within the subfolders, but not the subfolders themselves.

    So what we do is RD c:\mypath /s /q

    That will remove the "mypath" folder and all files and subfolders quietly.

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: eruberts@sjconsultant.com
  • Ok. I have a sub question about this.

    I have an ftp site that people upload and forget files on here constantly.

    Can anyone help with a script that will search a root folder (named data) and all subfolders (underneath data folder) to delete any files that are older then say 30 days from the date the script is run?

    So if i run it once a month, i would like it to check all folders and delete any file older than today's date.

    Anyone have something like this already before i research any more?

    Dave
    daveallen@hunsaker.com

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: Hunsaker
  • Hunsaker
    Ok. I have a sub question about this.

    I have an ftp site that people upload and forget files on here constantly.

    Can anyone help with a script that will search a root folder (named data) and all subfolders (underneath data folder) to delete any files that are older then say 30 days from the date the script is run?

    So if i run it once a month, i would like it to check all folders and delete any file older than today's date.

    Anyone have something like this already before i research any more?

    Dave
    daveallen@hunsaker.com


    Create a Kaseya script that executes the native FORFILES command. Use FORFILES /? in a CMD box for the proper syntax of the command. Use the /D -30 switch.

    For example: forfiles /p c:\data /s /d -30 /c "cmd /c del @path"

    Be careful with this one, it will delete all files over 30 days old in the folder c:\data and all subdirectories.

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: pcmnetmanage