Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1089271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:11:46+00:00 2026-05-16T23:11:46+00:00

I have written the following script below – I am not quite happy with

  • 0

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…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T23:11:47+00:00Added an answer on May 16, 2026 at 11:11 pm

    You can use a loop, checking for indexes of '/' and using them to get parts of the full path.

    var cmd = '';
    var j, k;
    var subpath;
    
    if (ftpmkdir.length < 1 || ftpmkdir === '/') {
        throw 'no path';
    }
    
    j = ( ftpmkdir.indexOf('/', 0) === 0 ) ? 1 : 0; // provides non-slash starting point
    k = ftpmkdir.indexOf('/', j);
    
    while (k != -1) {
        subpath = ftpmkdir.substr(j, k - j); // get the path up to the current slash
        cmd += " mkdir " + subpath + "\n";
        k = ftpmkdir.indexOf('/', k + 1); ; // move the cursor
    }
    
    // check for additional path after last slash mark
    if ((subpath + '/').length !== ftpmkdir.length - j) {
        cmd += " mkdir " + ftpmkdir.substr(j, ftpmkdir.length - j) + "\n";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written the following function in a bash script but it is not
I have written a KornShell (ksh) script that sets an array the following way:
I have written a Perl script for the following bioinformatics question, but unfortunately there
I have written the following Perl script- use HTML::TreeBuilder; my $html = HTML::TreeBuilder->new_from_content(<<END_HTML); <span
Below is the script I have written to change the value of one of
I have written the following script to search for a motif(substring) in a protein
I have written the following script. It opens a file, reads each line from
I have written following script in python which works fine: from sys import argv
I have written the following really simple python script to change the desktop wallpaper
I have written the following contact form validation script. How can I validate a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.