Archives
- July 2019
- January 2019
- November 2018
- August 2018
- July 2018
- February 2018
- November 2017
- October 2017
- July 2017
- June 2017
- May 2017
- April 2017
- January 2017
- December 2016
- November 2016
- August 2016
- January 2015
- December 2014
- March 2014
- April 2013
- December 2010
- November 2009
- September 2009
- June 2009
- March 2009
- February 2009
- November 2008
- October 2008
- August 2008
- July 2008
- January 2008
How to delete all the sub-directories in a directory
12th August 2018Recently we received a question from a customer that was using a set of IP cameras and a central FTP server where the cameras stored their recorded videos. As the cameras generate a lot of data they wanted to schedule an FTP script that deletes all the sub-folders of a given folder.
The script is pretty straightforward, all it is needed is to use GETLIST to retrieve the list of sub-directories, then use FOREACH and RMDIR to delete each one:
# Connect to FTP server OPENHOST("ftp.myhost.com","myuser","mypass") # Change current remote directory CHDIR("/www/Cameras") # Get all the subdirectories GETLIST($list,REMOTE_DIRECTORIES) # For each directory run the RMDIR command FOREACH $item IN $list RMDIR($item) END FOREACH # Finished, close the connection CLOSEHOST