Hello,

This will be my first time using Perl and I am hoping those with more experience may be able to help with some advice on which commands to use.

I would like to write a small script that will:

1) Find the directory that the script is being run from and save the path, for example $ScriptDir may be C:\PerlScripts

2) Go through each of the subdirectories, one level, and save the full path of the largest sized .txt file in each subdirectory to a new/appended string for example $FilePaths.

To clarify, say that there are 3 subdirectories in the directory that the script is in. Each of the three folders contains 5 .txt files. I would like to end up with a single string containing 3 full path names separated by spaces, the largest single .txt file from each subdirectory. For example, $FilePaths would be "C:\PerlScripts\SubDir1\File1.txt C:\PerlScripts\SubDir2\File2.txt C:\PerlScripts\SubDir3\File3.txt"

3) Create a new subdirectory under the script's path, for example $ScriptDir\NewFolder

4) Execute a command line command (this will be in Windows 7 so similar to a cmd.exe command) using $ScriptDir\NewFolder, for example:

MyProgram.exe --options $FilePaths $ScriptDir\NewFolder

Where $FilePaths is the files to run the MyProgram.exe on, and $ScriptDir\NewFolder is where to save the output.

If someone could please help with directing me to which functions to use, particularly for sorting files by size and obtaining a list of the largest file in each subdirectory as a string separated by spaces, I would be tremendously appreciative. Please let me know if there is any more info I can provide.

Thank you


In reply to Advice/help with beginner script (file sorting, execute command line command) by UserMane

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.