DssTrainer Posted March 21, 2007 Share Posted March 21, 2007 (edited) How would I go about getting the newest created folder in a path I have a path C:\mybackups\<UnknownDirName> I don't know what name the directory will have but I do know that it will always be the newest directory so i want to loop thru and find the creation dates of all the available folders and use the directory with the newest date. Edited March 21, 2007 by DssTrainer Link to comment Share on other sites More sharing options...
Uten Posted March 21, 2007 Share Posted March 21, 2007 Take a look at FileFindFirstFile, FileFindNextFile, FileGetAttrib and FileGetTime in the help file. Please keep your sig. small! Use the help file. Search the forum. Then ask unresolved questions :) Script plugin demo, Simple Trace udf, TrayMenuEx udf, IOChatter demo, freebasic multithreaded dll sample, PostMessage, Aspell, Code profiling Link to comment Share on other sites More sharing options...
jinxter Posted March 22, 2007 Share Posted March 22, 2007 You could also use the dir command.dir *.* /O-D /AD /TC /B will give you the last created directory first in a bare format list. If you then use it to create a file you can use FileReadLine() to get the name of the directory. > there are 10 types of people in the world, those who understand binary and those who don't. Link to comment Share on other sites More sharing options...
DssTrainer Posted March 26, 2007 Author Share Posted March 26, 2007 Thanks for your help guys! I tried both way and used some other code i found on the forums with jinx' dir command. The result: Func GetLastFolderDate($ParentFolderPath) Dim $aFiles[30000] $aRaw = Run(@ComSpec & " /c dir " & $ParentFolderPath & " /O-D /AD /TC /B", $ParentFolderPath, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) While 1 $SLine = StdoutRead($aRaw) If @error Then ExitLoop $aLine = StringSplit($SLine, @CRLF) If $aLine[0] > 1 Then For $i = 1 To $aLine[0] If $aLine[$i] = "" Then Continueloop $iLine = $iLine + 1 $aFiles[$iLine] = $aLine[$i] Next Else $iLine = $iLine + 1 $aFiles[$iLine] = $sLine return $aFiles[$iLine] EndIf Wend EndFunc Works perfect and fast. Thanks again! Link to comment Share on other sites More sharing options...
MrCreatoR Posted March 26, 2007 Share Posted March 26, 2007 (edited) Try this one: #include <File.au3> $Path = @ScriptDir $GetNewestDir = _NewestDir($Path, 1) MsgBox(0, "", "The newest dir <" & $GetNewestDir[1] & "> date is [" & $GetNewestDir[2] & "]") Func _NewestDir($sPath, $Flag=0) If Not FileExists($sPath) Then Return SetError(1, 0, -1) If Not StringInStr(FileGetAttrib($sPath), "D") Then Return SetError(2, 0, -1) Local $dList = _FileListToArray($sPath, "*", 2) If Ubound($dList) > 1 Then Local $NewstDir = $dList[1], $GetNewstDirTime = 0, $GetDirTime, $iArr 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 Local $NewstDirTimeArr = FileGetTime($sPath & "\" & $NewstDir, $Flag, 0) If IsArray($NewstDirTimeArr) Then _ $NewstDirTimeArr = $NewstDirTimeArr[2] & "/" & $NewstDirTimeArr[1] & "/" & $NewstDirTimeArr[0] Local $RetArr[3] = [2, $NewstDir, $NewstDirTimeArr] Return $RetArr Else Return SetError(1, 0, -2) EndIf EndFunc Edited March 26, 2007 by MsCreatoR Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: 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 ProgramUDFs: 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 Examples: 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 ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
DssTrainer Posted March 27, 2007 Author Share Posted March 27, 2007 (edited) Try this one: #include <File.au3> $Path = @ScriptDir $GetNewestDir = _NewestDir($Path, 1) MsgBox(0, "", "The newest dir <" & $GetNewestDir[1] & "> date is [" & $GetNewestDir[2] & "]") Func _NewestDir($sPath, $Flag=0) If Not FileExists($sPath) Then Return SetError(1, 0, -1) If Not StringInStr(FileGetAttrib($sPath), "D") Then Return SetError(2, 0, -1) Local $dList = _FileListToArray($sPath, "*", 2) If Ubound($dList) > 1 Then Local $NewstDir = $dList[1], $GetNewstDirTime = 0, $GetDirTime, $iArr 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 Local $NewstDirTimeArr = FileGetTime($sPath & "\" & $NewstDir, $Flag, 0) If IsArray($NewstDirTimeArr) Then _ $NewstDirTimeArr = $NewstDirTimeArr[2] & "/" & $NewstDirTimeArr[1] & "/" & $NewstDirTimeArr[0] Local $RetArr[3] = [2, $NewstDir, $NewstDirTimeArr] Return $RetArr Else Return SetError(1, 0, -2) EndIf EndFunc Thx for the code. It's quite a bit slower than the dir method, but might be good for an alternative via radio button or something in case something doesn't work right with the dir method. Edited March 27, 2007 by DssTrainer 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