Jump to content
Sign in to follow this  
AutoMT

Search under folder with unspecified name

Recommended Posts

AutoMT

Hi there, I'm writing a script that will be placed on all the computers in a network to monitor the size of a folder on a drive. The folder is usually something like

D:\FIFO\13\2007_11_14\18

which is

D:\FIFO\[channel]\[year_month_date]\[hour]

This is the line I'm using:

$point1 = DirGetSize("D:\FIFO\13\" & @year & "_" & @MON & "_" & @MDAY & "\" & @HOUR)

However, the number in bold, 13, is sometimes a different number on certain machines, and rather than write a separate script for each machine, I'd like to know if there's any way I can make it search in any folder under the D:\FIFO directory.

Share this post


Link to post
Share on other sites
Nahuel

If there's only ONE folder under FIFO, then try this:

#include <File.au3>
$FileList=_FileListToArray ( "D:\FIFO\","",2)
$point1 = DirGetSize($FileList[1] & @year & "_" & @MON & "_" & @MDAY & "\" & @HOUR)

Share this post


Link to post
Share on other sites
AutoMT

Sorry - I forgot to say, there are four different folders under FIFO...

Share this post


Link to post
Share on other sites
Nahuel

-edit-

This should work:

Global $FolderName
#include <File.au3>
$FileList=_FileListToArray ( "D:\FIFO\","*",2)
For $i=1 To $FileList[0]
    $TestDir=_FileListToArray ("D:\FIFO\" & $FileList[$i],"*",2)
    If Not IsArray($TestDir) Then ContinueLoop
    For $a=1 To $TestDir[0]
        If StringInStr($TestDir[$a],@year & "_" & @MON & "_" & @MDAY ) Then
            $FolderName=$FileList[$i];$FileList[$i] is the name of the folder you want
            ExitLoop(2)
        EndIf
    Next
Next

MsgBox(0,"",$FolderName)
$point1 = DirGetSize("D:\FIFO\" & $FolderName & "\" & @year & "_" & @MON & "_" & @MDAY & "\" & @HOUR)
MsgBox(0,"",$point1)
Edited by Nahuel

Share this post


Link to post
Share on other sites
AutoMT

-edit-

This should work:

The first thing you had up worked a treat, this thing:

#include <File.au3>
    $FileList=_FileListToArray ( "D:\FIFO\","*",2)
    For $i=1 To $FileList[0]
        $SplitPath=StringSplit($FileList[$i],"\")
        $FolderName=$SplitPath[$SplitPath[0]]
        If StringRegExp($FolderName,"(i?)[^a-z][0-9]") Then
            $folder=$FolderName
            ExitLoop
        EndIf
    Next

However I've found a few computers that have a FIFO directory on their C drive instead of D. I'm trying to make it so the script will check the C drive if it cannot find anything on the D drive - by pretty much duplicating that code under a different function except changing it to C:\FIFO instead of D. However I don't know if this is the right thing to do because I am getting this error:

>"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Documents and Settings\taylorsu\Desktop\AlertStage.au3"

C:\Documents and Settings\taylorsu\Desktop\AlertStage.au3 (63) : ==> Subscript used with non-Array variable.:

For $i=1 To $FileList[0]

For $i=1 To $FileList^ ERROR

>Exit code: 1 Time: 8.864

Since I'm not entirely sure what the code is doing, I can't really figure out what the problem is (I'm new at this :/).

Share this post


Link to post
Share on other sites
PsaltyDS

The first thing you had up worked a treat, this thing:

However I've found a few computers that have a FIFO directory on their C drive instead of D. I'm trying to make it so the script will check the C drive if it cannot find anything on the D drive - by pretty much duplicating that code under a different function except changing it to C:\FIFO instead of D. However I don't know if this is the right thing to do because I am getting this error:

Since I'm not entirely sure what the code is doing, I can't really figure out what the problem is (I'm new at this :/).

You just need a test to make sure the search was successful before wading into the array:

#include <File.au3>
$FileList = _FileListToArray("D:\FIFO\", "*", 2)
If @error Then
    MsgBox(16, "Error", "No files listed")
Else
    For $i = 1 To $FileList[0]
        $SplitPath = StringSplit($FileList[$i], "\")
        $FolderName = $SplitPath[$SplitPath[0]]
        If StringRegExp($FolderName, "(i?)[^a-z][0-9]") Then
            $folder = $FolderName
            ExitLoop
        EndIf
    Next
EndIf

:P


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
AutoMT

You just need a test to make sure the search was successful before wading into the array:

That's awesome, it works great now!

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.