#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    14
    Rep Power
    0

    Need to split string and get the specific directory list as an array


    I need to split the drive which I am getting as a string as shown below :

    L:\Pom_changes\sandbox\VVD\moocs/apps/Times/mooc-main/apacheL:\Pom_changes\sandbox\VVD\moocs/apps/Times/mooc-main/cloudscriptsL:\Pom_changes\sandbox\VVD\moocs/apps/Times/mooc-main/mdcsserverL:\Pom_changes\sandbox\VVD\moocs/apps/Times/mooc-main/mlseduL:\Pom_changes\sandbox\VVD\moocs/apps/Times/mooc-main/mrm-webappL:\Pom_changes\sandbox\VVD\moocs/apps/Times/mooc-main/srcL:\Pom_changes\sandbox\VVD\moocs/apps/Times/mooc-main/ufrL:\Pom_changes\sandbox\VVD\moocs/apps/Times/mooc-main/worker-webappL:\Pom_changes\sandbox\VVD\moocs/libs/mlslibs/mooc-main/matlab_codeL:\Pom_changes\sandbox\VVD\moocs/libs/mlslibs/mooc-main/stateless-servicesL:\Pom_changes\sandbox\VVD\moocs/test/json_integration_tests/mooc-main/api_integration_testsL:\Pom_changes\sandbox\VVD\moocs/test/json_integration_tests/mooc-main/api_test_toolsL:\Pom_changes\sandbox\VVD\moocs/test/json_integration_tests/mooc-main/router_json_integration_testsL:\Pom_changes\sandbox\VVD\moocs/test/mooc-deploy-and-test/mooc-main/src

    Not getting any clue.Please help

    Thanks,
    Vaibhav
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,968
    Rep Power
    1225
    Your question does not make any sense. Please rephrase your question and post your code.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    14
    Rep Power
    0
    Originally Posted by FishMonger
    Your question does not make any sense. Please rephrase your question and post your code.

    I am trying to get the path which has directory "mooc-main" and its child directory path from the below code


    my $rootdir = $ARGV[0]; # $ARGV[0] Root Directory Path
    my @dirs = ();
    my $index = 0;


    find(sub {
    return unless -d;
    if (basename($File::Find::dir) =~ /mooc-main/i) {
    process($File::Find::name);
    }
    }, $rootdir);

    and I am getting the O/P of $File::Find::name as

    "L:\Pom_changes\sandbox\VVD\moocs/apps/Times/mooc-main/apacheL:\Pom_changes\sandbox\VVD\moocs/apps/Times/mooc-main/cloudscriptsL:\Pom_changes\sandbox\VVD\moocs/apps/Times/mooc-main/mdcsserverL:\Pom_changes\sandbox\VVD\moocs/apps/Times/mooc-main/mlseduL:\Pom_changes\sandbox\VVD\moocs/apps/Times/mooc-main/mrm-webappL:\Pom_changes\sandbox\VVD\moocs/apps/Times/mooc-main/srcL:\Pom_changes\sandbox\VVD\moocs/apps/Times/mooc-main/ufrL:\Pom_changes\sandbox\VVD\moocs/apps/Times/mooc-main/worker-webappL:\Pom_changes\sandbox\VVD\moocs/libs/mlslibs/mooc-main/matlab_codeL:\Pom_changes\sandbox\VVD\moocs/libs/mlslibs/mooc-main/stateless-servicesL:\Pom_changes\sandbox\VVD\moocs/test/json_integration_tests/mooc-main/api_integration_testsL:\Pom_changes\sandbox\VVD\moocs/test/json_integration_tests/mooc-main/api_test_toolsL:\Pom_changes\sandbox\VVD\moocs/test/json_integration_tests/mooc-main/router_json_integration_testsL:\Pom_changes\sandbox\VVD\moocs/test/mooc-deploy-and-test/mooc-main/src"


    but I need individual paths not all as a string.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,968
    Rep Power
    1225
    $File::Find::name would not return a string like that. Show us your process() sub and the section of code that outputs that string if it's not in the process() sub.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    14
    Rep Power
    0
    Originally Posted by FishMonger
    $File::Find::name would not return a string like that. Show us your process() sub and the section of code that outputs that string if it's not in the process() sub.
    my process sub is


    sub process {
    my @list = shift;
    $list =~ s/mooc-main/$newdirname/i;
    $list=~ s/\//\\/g;
    print $list;
    mkdir $list \n";
    chdir $list;

    }
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,968
    Rep Power
    1225
    @list and $list are 2 entirely different vars. Where are you assigning $list?

    Please post your entire script.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    14
    Rep Power
    0
    Originally Posted by FishMonger
    @list and $list are 2 entirely different vars. Where are you assigning $list?

    Please post your entire script.
    There you go


    use strict;
    use warnings;
    use File::Find;
    use File::Basename qw/ basename /;


    # Check the Input Parameters
    if ($#ARGV != 1 ) {
    print "usage: perl branchNrelease.pl Rootdirectorypath \n";
    exit;
    }
    my $rootdir = $ARGV[0]; # Project Root Directory Path
    my $newdirname = $ARGV[1];
    my @dirlist = ();

    find(sub {
    return unless -d;
    if (basename($File::Find::dir) =~ /mooc-main/) {
    process($File::Find::name);
    }
    }, $rootdir);

    sub process {
    my $list = shift;
    $list =~ s/mooc-main/$newdirname/i;
    $list =~ s/\//\\/g;
    print $list . "\n";
    mkdir $list;
    chdir $list;
    }

    I didn't know how to do indentation in the message so please tell me how to post the indent version of my script.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,968
    Rep Power
    1225
    I didn't know how to do indentation in the message
    Use the code tags (which is the # button abouve the post box) around your code.

    Now that you've changed your script, what output are you now getting and how does that differ from what you expect and what are the 2 args that you're passing to the script?
    Last edited by FishMonger; July 26th, 2013 at 03:55 PM.
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    14
    Rep Power
    0
    Originally Posted by FishMonger
    Use the code tags (which is the # button abouve the post box) around your code.

    Now that you've changed your script, what output are you now getting and how does that differ from what you expect and what are the 2 args that you're passing to the script?
    The two arguments are

    first one rootdirectory from where to start the search.

    Second one i am using to create a new directory with the name as $newdirname at the same place where we found mooc-main and its sub directories


    and what is happening I am unable to create new directory as the $list has values as


    " L:\Pom_changes\sandbox\VVD\moocs\apps\Times\mooc-main\apacheL:\Pom_changes\sandbox\VVD\moocs\apps\Times\mooc-main\cloudscriptsL:\Pom_changes\sandbox\VVD\moocs\apps\Times\mooc-main\mdcsserverL:\Pom_changes\sandbox\VVD\moocs\apps\Times\mooc-main\mlseduL:\Pom_changes\sandbox\VVD\moocs\apps\Times\mooc-main\mrm-webappL:\Pom_changes\sandbox\VVD\moocs\apps\Times\mooc-main\srcL:\Pom_changes\sandbox\VVD\moocs\apps\Times\mooc-main\ufrL:\Pom_changes\sandbox\VVD\moocs\apps\Times\mooc-main\worker-webappL:\Pom_changes\sandbox\VVD\moocs\libs\mlslibs\mooc-main\matlab_codeL:\Pom_changes\sandbox\VVD\moocs\libs\mlslibs\mooc-main\stateless-servicesL:\Pom_changes\sandbox\VVD\moocs\test\json_integration_tests\mooc-main\api_integration_testsL:\Pom_changes\sandbox\VVD\moocs\test\json_integration_tests\mooc-main\api_test_toolsL:\Pom_changes\sandbox\VVD\moocs\test\json_integration_tests\mooc-main\router_json_integration_testsL:\Pom_changes\sandbox\VVD\moocs\test\mooc-deploy-and-test\mooc-main\src"
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,968
    Rep Power
    1225
    The two arguments are

    first one rootdirectory from where to start the search.

    Second one i am using to create a new directory with the name as $newdirname
    That's obvious. I wanted to know the actual values.


    The only way for you to get that output would be if you didn't include \n in the print statement.

    Your script has a number of problems, but lets first clear up your understanding of the value for $list.

    Try this adjusted version and post the output within the code tags.
    Code:
    use strict;
    use warnings;
    use File::Find;
    use File::Basename qw/ basename /;
    use Data::Dumper;
    
    
    # Check the Input Parameters
    if ($#ARGV != 1 ) {
        print "usage: perl branchNrelease.pl Rootdirectorypath \n";
        exit;
    }
    my $rootdir = $ARGV[0]; # Project Root Directory Path
    my $newdirname = $ARGV[1];
    my @dirlist = ();
    
    find(sub {
        return unless -d;
        if (basename($File::Find::dir) =~ /mooc-main/) {
            process($File::Find::name);
        }
    }, $rootdir);
    
    sub process {
        my $list = shift;
        print Dumper $list;
        $list =~ s/mooc-main/$newdirname/i;
        $list =~ s/\//\\/g;
        #print $list . "\n";
        mkdir $list;
        chdir $list;
    }

IMN logo majestic logo threadwatch logo seochat tools logo