ProVide can run a Windows CMD (.cmd) batch script automatically when a file finishes uploading or downloading, using the Events and Messages module. This page gives two working examples: deleting a file after it’s downloaded, and deleting an uploaded file if it’s empty (0 bytes). The Events and Messages module is available from the Maxi license.
Both examples use the %EXECUTE(...)% token in an event’s message field to call your script, and pass %LOCAL_FILENAME% (the full path to the file) as an argument.
Example 1: delete a file after it has been downloaded #
This script deletes a file from the server once a user has finished downloading it.
@echo off
REM Set FILE to the first argument passed to the script
set FILE=%1
REM Remove surrounding quotes
for /f "usebackq tokens=*" %%a in ('%FILE%') do set FILE=%%~a
REM Delete the file
DEL "%FILE%"
exit 0
Set it up like this:
- Save the script as a
.cmdfile with a clear name, such asOnDownloadEndScript.cmd, and place it in a dedicated scripts folder. - In the ProVide admin interface, open “Events and Messages” under the first tab.
- In the Events and Messages window, open the drop-down menu and select “OnDownloadEnd.” Anything you put in the message field is either written to the server log or used to execute scripts, including passing arguments.
In the message area, enter:
%EXECUTE("C:\PATH\TO\SCRIPT\OnDownloadEndScript.cmd" "%LOCAL_FILENAME%")%
This runs your script after each download completes and passes %LOCAL_FILENAME%, the full path to the file that was downloaded.
Example 2: delete an uploaded file if it is 0 bytes #
This script checks whether an uploaded file is empty and deletes it if so.
@echo on
REM Set FILE to the first argument passed to the script
set FILE=%1
REM Remove surrounding quotes
for /f "usebackq tokens=*" %%a in ('%FILE%') do set FILE=%%~a
REM Delete the file if its size is 0 bytes
if %~z1 == 0 (DEL "%FILE%")
exit 0
Follow steps 1 and 2 from the first example, but give the script a fitting name such as OnUploadEndScript.cmd. In step 3, choose “OnUploadEnd” instead of “OnDownloadEnd” so the script runs after each upload.
In the message area, enter:
%EXECUTE("C:\PATH\TO\SCRIPT\OnUploadEndScript.cmd" "%LOCAL_FILENAME%")%
The script now runs after a user uploads a file and receives %LOCAL_FILENAME%, the full path to the uploaded file, so it can check the size and remove the file if it is empty.
For a related walkthrough, see the Email example, which triggers an email from an event.