Hi choroba! Thank you for your input as always. I have a few questions:
1. As I understand the first part does opendir (somewhere) on the path my $path = path("/usr/vsa/pkgs/python3/3.6.3a/bin/python3.6"); and insert all of the files inside the directory into $paths but I'm interested only in the path itself. The input of the script is an array of paths. Each path (and only those paths) interest me. So if for example I have /usr/vsa/pkgs/python3/3.6.3a/bin/python3.6a (note the "a" at the end) and it does not exist in the array of paths, I don't want to copy it (only /usr/vsa/pkgs/python3/3.6.3a/bin/python3.6. See more info at (*)).
2. It does opendir for some reason so it fails for files (the path /usr/vsa/pkgs/python3/3.6.3a/bin/python3.6 is a file and it fails with: Error opendir on '/usr/vsa/pkgs/python3/3.6.3a/bin/python3.6': Not a directory at line 113). Line 113 is "{ recurse => 1 }"
3. It looks like path can't handle with some symlinks. I have a link /a -> /c/d/e and path("/a") returns nothing, while path("/a/b") returns paths under "/c/d/e/b".
4. Also what if there is a link /a/ -> /b/ -> /c? Should it work?

The cp/mkdir/ln part I will do myself. I'm just struggling to build the arrays of paths that are involved (and only them) - splitted into categories (file-links, dir-links, files, dirs).

* A bit more explanation about the "involved paths": I have an array @array=("/usr/vsa/pkgs/python3/3.6.3a/bin/python3.6", ...). I want to iterate over this array and mkdir the directories that exist in the array (recursively), copy the files (not the directories but I want to have only the paths that are located in @array) and set the same links. Think of that as a container which you want to run your tool on and you know those paths are needed for running your tool (but any other path is not needed). So if your tool uses /a/b/c.file and under /a/b you also have /a/b/d.file, then it will create /a/b directory and copy /a/b/c to $target/a/b/c (and set links if needed). If I wanted to copy all of the files under directory, I would just copy the directory (instead of mkdir and cp files under directory).

In reply to Re^5: Getting all subpaths from a path by ovedpo15
in thread Getting all subpaths from a path by ovedpo15

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.