Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2024-04-23 07:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found