CMD Examples

From ProVide DocWiki
Jump to: navigation, search

Example 1

For this example we shall make the server deletes a file from the server once it has been downloaded by a user.

The script we will be using for this example is the following:

@echo off

#  set the FILE to the first argument we provided the script with
set FILE=%1

# Remove quotes
for /f "useback tokens=*" %%a in ('%FILE%') do set FILE=%%~a

# Remove file
DEL "%FILE%"

exit 0


1. The first step once we've done the script is to first save it down to a '.cmd' file (name it something like OnDownloadEndScript to easily keep track of it) and save it in a script folder.

2. To make this script trigger after a file has been downloaded from the server we first need to go on the admin interface for our ProVide server and find "Events and Messages" under the first tab.

3. In the "Events and Messages" window we click on the drop-down menu and select "OnDownloadEnd". Everything in the message field will either be written to the server logg or we can execute scripts and even send arguments with it.

The text we will write in the message area of the "Events and Messages" window is the following:

%EXECUTE("C:\PATH\TO\SCRIPT\OnDownloadEndScript.cmd" "%LOCAL_FILENAME%")%


This will make the script that we just made execute after a file is done downloading, it will also provide the "%LOCAL_FILENAME%" which is the full path to the file that was used in the download.


Example 2

For the next example we will make a script that check if the file is 0 bytes and then deletes the file if it is 0 bytes.

The script we will be using for this example is the following:

@echo on

#  set the FILE to the first argument we provided the script with
set FILE=%1

# Remove quotes
for /f "useback tokens=*" %%a in ('%FILE%') do set FILE=%%~a

# Checks if file is equal to 0 bytes and deletes if the statement is true.
if %~z1 == 0 (DEL "%FILE%")

exit 0


Follow step 1 and 2 from the first example (just change the name to something more fitting like "OnUploadEndScript") and on the 3rd step change "OnDownloadEnd" to "OnUploadEnd" so it will trigger after a file has been uploaded so we can check what size it is and delete it if it's 0 bytes.


To make the script run we need to write the following in the "Events and Messages" message area:

%EXECUTE("C:\PATH\TO\SCRIPT\OnUploadEndScript.cmd" "%LOCAL_FILENAME%")%


Now the script will run after a user has uploaded a file and it will provide the %LOCAL_FILENAME% (the full path to the file uploaded) to the script so that we can check if it's 0 bytes in the script.

If you wish to read more about this subject you can go to our Email example.