Jump to content

Recommended Posts

Posted

Hello,

I am testing one application which will create a result data folder after running. How can I get the name of the lastest created folder in my Autoit script? Deep appreciate any help!

Pingping

Posted

  goupingping said:

Hello,

I am testing one application which will create a result data folder after running. How can I get the name of the lastest created folder in my Autoit script? Deep appreciate any help!

Pingping

_FileListToArray() with flags! Then FileGetTime(). Probably also _DateDiff().

Maybe easier:

Run() Command: "dir /b /AD /OD" and parse output.

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Posted

Thank you very much! I still have problems as:

1) My script is

$val = RunWait(@COMSPEC & " /c Dir C:\", @SW_MAXIMIZE )

I got this error message:

==> Unable to execute the external program.:

$val = RunWait(@COMSPEC & " /c Dir C:\", @SW_MAXIMIZE )

The directory name is invalid.

2) How can I parse the result after I run the Dos command successfully?

Thank you!

Pingping

Posted

@1:

looks kidna like your commanline interprater isnt there...what about just a standard thing like Run(@ComSpec & " /c " & 'ipconfig', "", @SW_MAXIMIZE) ?

@2: could get it in a text file and do some data managing add a "> somefile.txt" after a dos command to rerout the output to a text file...or use StdoutRead...

Posted

RunWait(@COMSPEC & " /c dir /A:D /B /O:D """ & $dirtosearch & """ >> News.log", $dirtosearch )

Then there will be a file News.log where the folders are named i date...

Start here if you are new Valuater's AutoIT 1-2-3Looking for an UDF - Look hereDo you need to do it twice - Autoit

Posted

Here is something to start....

#include <Constants.au3>
#include <Array.au3>

$dir = "C:\"
$foo = Run(@ComSpec & " /c dir /B /OD /AD " & $dir, @SystemDir, @SW_HIDE, $STDOUT_CHILD)

$line = ""

While 1
    $line &= StdoutRead($foo)
    If @error Then ExitLoop
Wend

$lines = StringSplit(StringStripCR($line),@LF)
_ArrayDisplay($lines,"Folders in " & $dir)

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Posted

Here is example of _NewestDir() function (whitout using a cmd) :

#include <File.au3>
$Path = @ScriptDir & "\test"
$GetNewestDir = _NewestDir($Path, 1)

If $GetNewestDir = -1 Then
    MsgBox(48, "Error", "The path <" & $Path & "> was not found")
ElseIf $GetNewestDir = -2 Then
    MsgBox(48, "Error", "There is no folders in path <" & $Path & ">")
Else
    MsgBox(64, "Newest folder results", "The newst folder in path <" & $Path & "> is [" & $GetNewestDir & "]")
EndIf

;Return -1 if given path is not exists, return -2 if there is no folders in the path, else return the name of latest folder in the path
;By default returned last Modified folder, see this flags:
;0 = Modified (default)
;1 = Created
;2 = Accessed
Func _NewestDir($sPath, $Flag=0)
    If Not FileExists($sPath) Then Return -1
    Local $dList = _FileListToArray($sPath, "*", 2)
    If IsArray($dList) Then
        Local $NewstDir = $dList[1], $GetNewstDirTime = 0
        For $iArr = 1 To $dList[0]
            $GetDirTime = FileGetTime($sPath & "\" & $dList[$iArr], $Flag, 1)
            If $GetDirTime > $GetNewstDirTime Then $NewstDir = $dList[$iArr]
            $GetNewstDirTime = FileGetTime($sPath & "\" & $NewstDir, $Flag, 1)
        Next
        Return $NewstDir
    Else
        Return -2
    EndIf
EndFunc

 

  Reveal hidden contents

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...