I have written the following script below - I am not quite happy with the script as I think it could be written in a more elegant and dynamic way...
I am using ftp.exe
to ftp files from my application to another server.
If the folder structure does not exists on the web site. I need to create the folder stucture...
and doing it this way
mkdir folder1
mkdir folder1/folder2
mkdir folder1/folder2/folder3
with the script below I cater for a few folder
lengths but not unlimited... so the solution will only work up to a certain amount of sub folders
.
ftpmkdirlength = ftpmkdir.split('/').length-1
var i=0;
for (i=0;i<=ftpmkdirlength;i++)
{
ftpmkdir0 = " mkdir " + ftpmkdir.match(/\/.*?\//) + "\n";
ftpmkdir1 = " mkdir " + ftpmkdir.match(/\/.*?\/.*?\//) + "\n";
ftpmkdir2 = " mkdir " + ftpmkdir.match(/\/.*?\/.*?\/.*?\//) + "\n";
ftpmkdir3 = " mkdir " + ftpmkdir.match(/\/.*?\/.*?\/.*?\/.*?\//) + "\n";
ftpmkdir4 = " mkdir " + ftpmkdir.match(/\/.*?\/.*?\/.*?\/.*?\/.*?\//) + "\n";
ftpmkdir5 = " mkdir " + ftpmkdir.match(/\/.*?\/.*?\/.*?\/.*?\/.*?\/.*?\//) + "\n";
ftpmkdir6 = " mkdir " + ftpmkdir.match(/\/.*?\/.*?\/.*?\/.*?\/.*?\/.*?\/.*?\//) + "\n";
ftpmkdir7 = " mkdir " + ftpmkdir.match(/\/.*?\/.*?\/.*?\/.*?\/.*?\/.*?\/.*?\/.*?\//) + "\n";
ftpmkdir8 = " mkdir " + ftpmkdir.match(/\/.*?\/.*?\/.*?\/.*?\/.*?\/.*?\/.*?\/.*?\/.*?\//) + "\n";
ftpmkdir9 = " mkdir " + ftpmkdir.match(/\/.*?\/.*?\/.*?\/.*?\/.*?\/.*?\/.*?\/.*?\/.*?\/.*?\//) + "\n";
ftpmkdir10 = " mkdir " + ftpmkdir.match(/\/.*?\/.*?\/.*?\/.*?\/.*?\/.*?\/.*?\/.*?\/.*?\/.*?\/.*?\//) + "\n";
ftpmkdir1 = " mkdir " + ftpmkdir + ftpmkdir0 + ftpmkdir1 + ftpmkdir2 + ftpmkdir3 + ftpmkdir4 + ftpmkdir5 + ftpmkdir6 + ftpmkdir7 + ftpmkdir8 + ftpmkdir9+ ftpmkdir10;
ftpmkdir1 = ftpmkdir1.replace(/mkdir null/ig, '');
How can I make it more dynamic? so that the script see how many folders the input contains...
I can see the folders full length
and get the folder like this /folder1/folder2/folder3
but need to strip it to
folder1
folder1/folder2/
folder1/folder2/folder3/
and then create it...