CMD Examples

Table of Contents

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.

onDownloadEnd-provide-server

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.

Thank you for downloading ProVide Server

For the ultimate experience of ProVide’s features and functions, we recommend choosing the MAXI License.

Follow the 3 easy steps below to install ProVide Server

Your Cart

Header test Qty Price
display quantity price
Product Name Qty Price

Explore ProVide with a Free 30-Day Trial!

Discover our innovative product with a complimentary trial, gaining full access to all its features. This trial empowers you to enhance productivity, streamline operations, and improve customer experiences. After the trial, continue effortlessly with us or let the license expire without obligations.

Join many satisfied users and witness significant improvements. Claim your free trial now and see the impact yourself.

Once you request your trial a registration form will popup where you can enter your contact details. This will be the email to which your trial license will be delivered.

Try ProVide today!
Subtotal: Total
Total (inc. VAT): Total
Tax: Total
You save: Total

Contact our Product Specialist

Fill in the form below to book a 30 min no-obligation consulting session.

I will reply within 24 hours.

General Inquiry

Fill in the form below and our team will be happy to assist you

Office Hours

Monday-Friday:
8:00am to 5:00pm (EST)

Address

Farsight Tech Nordic AB
Kaplansgatan 16B
3:e Våningen
541 34 Skövde

Medi trial

Thank you for showing interest in trying ProVide Server

Follow the 3 easy steps below to install ProVide Server

Maxi trial

Thank you for showing interest in trying ProVide Server

Follow the 3 easy steps below to install ProVide Server

Free Trial

Get
ProVide Software