UserMane Posted April 19, 2014 Share Posted April 19, 2014 (edited) Hello, I would like to write a small program/script and am looking for advice on how to do so. I do not have a preference about which method or language to use, hopefully looking for the simplest way to do this (if it works with Windows or DOS command line this is preferable). I have a program that runs on text files e.g. "program file1.txt file2.txt" I have 20 folders that each have 5-10 text files. I want to automatically get the name of the largest size text file from each of the 20 folders, and then run the program on these 20 files as described above. Ideally I could point my script to a folder, and it will automatically find the largest .txt file in each of the subdirectories and run "program file1.txt file2.txt file3.txt ..." Any ideas on how to most efficiently accomplish this? Ideas or links to tutorials if applicable are helpful. Thank you Edited April 19, 2014 by UserMane Link to comment Share on other sites More sharing options...
somdcomputerguy Posted April 20, 2014 Share Posted April 20, 2014 Welcome to the forum. http://www.autoitscript.com/autoit3/docs/ - Good place to start. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 20, 2014 Moderators Share Posted April 20, 2014 UserMane,Welcome to the AutoIt forum. But please pay attention to where you post - the "Dev Chat" section where you started this thread is not for general support questions. I have moved it for you, but would ask you to be more careful in future. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
sahsanu Posted April 20, 2014 Share Posted April 20, 2014 (edited) Here just an example to get an array for file with max size in each of the 20 dirs. The first part of the script is just to create 20 dirs and files inside them with random text to make them different in size. The script is commented, anyway if you have any doubt don't hesitate to ask. Of course, if someone can show any easy way to perform the task, he/she will be welcome (all os us are here to learn) ;-) expandcollapse popup#include <String.au3> #include <Array.au3> #include <File.au3> Local $aListDirsToSearchIn[20] ;You should create this array with the list of dirs you want to search in ;This part is just to create 20 dirs and 5 to 10 files with random size per directory just for the example For $i = 1 To 20 $sDirectory = @ScriptDir & "\directory" & StringFormat("%02d", $i) DirCreate($sDirectory) For $j = 1 To Random(5, 10, 1) $sFile = $sDirectory & "\file" & StringFormat("%02d", $j) & ".txt" $sString = StringReplace(_StringRepeat("Filling file " & $sFile & @CRLF, Random(1, 1000, 1)), @CRLF, "", -1) FileWrite($sFile, $sString) Next $aListDirsToSearchIn[$i - 1] = $sDirectory Next ;End of creating the dirs and files structure for the example Local $aResultList[UBound($aListDirsToSearchIn)][2] ;Define the array where the max size file on each dir will be stored For $i = 1 To UBound($aListDirsToSearchIn) ;Loop each dir to search the files inside it Local $aListFiles = _FileListToArray($aListDirsToSearchIn[$i - 1], "*.txt", 1, True) ;Retrieve the files in dir Local $aSortingFiles[$aListFiles[0]][2];Define a 2D array where we will store the file name on column 0 ans size in column 1 For $j = 1 To UBound($aSortingFiles) - 1 ;Loop the 2D array filling the rows and columns with file name and size Local $iSize = FileGetSize($aListFiles[$j]) $aSortingFiles[$j - 1][0] = $aListFiles[$j] $aSortingFiles[$j - 1][1] = $iSize Next _ArraySort($aSortingFiles, 1, Default, Default, 1) ;Sort the column 1 (size) descencing $aResultList[$i - 1][0] = $aSortingFiles[0][0] ;Fill the final array with file name that has max file in dir $aResultList[$i - 1][1] = $aSortingFiles[0][1] ;Fill the final array with size for that file name Next _ArrayDisplay($aResultList) ;The resulting array will have a list with the max size file per directory and you could use for your needs ;This part is to remove the dirs and files created on @Scriptdir for the example, un commented them if you want to delete the dirs created #cs For $i = 1 To 20 $directory = @ScriptDir & "\directory" & StringFormat("%02d", $i) DirRemove($directory, 1) Next #ce The part to do whatever you want with the max size files list is up to you ;-) Edit: Typos Cheers, sahsanu Edited April 20, 2014 by sahsanu Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now