Sign in to follow this  
Followers 0
UserMane

Question about simple script?

4 posts in this topic

#1 ·  Posted (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 by UserMane

Share this post


Link to post
Share on other sites



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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (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) ;-)

#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 by sahsanu

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0