Jump to content

How to find out the lastest created folder?


Recommended Posts

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 *

Link to comment
Share on other sites

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

Link to comment
Share on other sites

@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...

Link to comment
Share on other sites

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 *

Link to comment
Share on other sites

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

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
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
 Share

  • Recently Browsing   0 members

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