May 19, 2014, 3:49 PM
Post #1 of 2
New Perl user, advice/help with beginner script (file sorting, execute command line command)
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.
(This post was edited by UserMane on May 19, 2014, 3:51 PM)