Script

FTP

The professional tool to automate FTP, SFTP, FTPS

and schedule FTP batch jobs

How to create a local folder using the current date



Dates can be written in multiple ways, not only because of the language used (English, Spanish, German…) but also within the same language we can write a date in many different ways. For example in English, we can write it as “20 October 2017”, 20/10/2017, 10/20/2017 etc.

In ScriptFTP the most common formats of dates are available in the GETTIME command but sometimes you need to retrieve the date or time components separately (month, day, year, hour…) and build your own expression of a date or time. In this example, it is shown how to build a date expression without spaces and using a three letter month, for example “20Jan2017”. We will then use it to create a local directory.

 

# Set the current local directory to C:\mycurrent_dir
LOCALCHDIR("c:\mycurrent_dir\")
 
# Get the current day, month and year as numbers
$day_number = GETTIME(DAY)
$month_number = GETTIME(MONTH)
$year_number = GETTIME(YEAR)
 
# Build the 3 letter month name based on the
# month number
$month_text = ""
 
IF($month_number=="1")
	$month_text = "Jan"
END IF
 
IF($month_number=="2")
	$month_text = "Feb"
END IF
 
IF($month_number=="3")
	$month_text = "Mar"
END IF
 
IF($month_number=="4")
	$month_text = "Apr"
END IF
 
IF($month_number=="5")
	$month_text = "May"
END IF
 
IF($month_number=="6")
	$month_text = "Jun"
END IF
 
IF($month_number=="7")
	$month_text = "Jul"
END IF
 
IF($month_number=="8")
	$month_text = "Aug"
END IF
 
IF($month_number=="9")
	$month_text = "Sep"
END IF
 
IF($month_number=="10")
	$month_text = "Oct"
END IF
 
IF($month_number=="11")
	$month_text = "Nov"
END IF
 
IF($month_number=="12")
	$month_text = "Dec"
END IF
 
# Build the folder name. It will lool like 12Oct2017
$foldername = $day_number.$month_text.$year_number
 
# Run the windows mkdir command, not the one from ScriptFTP
# to create a local directory. The MKDIR command from ScriptFTP
# is used to create remote directories. The LOCALMDKDIR command
# from ScriptFTP can be also used to create a local directory.
EXEC("mkdir ".$foldername)