Jump to content

Recommended Posts

Posted

Hello all...

 

I've been trying to come up with a way to create a script that shows the name of the the newest folder in this path C:\T-in  . i have tried to use the The FileGetTime and the _ArraySort to get only the name of one last modified folder but am still not good with loops -.- 

i am really thankful for your help

Posted
Quote

 

here it comes 

#include <file.au3>
#include <Array.au3>

Global $spath = ("C:\T-in")


$checkpath = StringRegExp($spath,"^.+\\$",0)
If $checkpath = 0 Then $spath = $spath & "\"

$aArray = _FileListToArray($spath,"*",$FLTAR_FOLDERS)


_ArraySort($aArray,1,1,"",1)




$folderName = ""
$Date = 9999999999999
For $i = 1 to UBound($aArray) - 1

   $FolderDate = FileGetTime($aArray[$i])
   If $FolderDate < $Date Then
        $Date = $FolderDate
        $folderName = $aArray[$i]
     EndIf

Next

 MsgBox(0, "Newest Folder ", "Newest Folder Created : " & $folderName)

i hope it makes things more easier and thanks for your fast response ^^

Posted

FileGetTime returns an array by default, you need to use the format parameter to have it return a string to do what you're trying to do.

$FolderDate = FileGetTime($aArray[$i], $FT_MODIFIED, $FT_STRING)

 

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Posted

The regex check for backslash is useless,  _FileListToArray does it internally

#include <File.au3>
#include <Array.au3>

Global $spath = @desktopdir  ;"C:\T-in"

; list folders
$aArray = _FileListToArray($spath, "*", $FLTAR_FOLDERS)
; insert a column
_ArrayColInsert ($aArray, 1)
; populate new column with times
For $i = 1 to $aArray[0][0]
   $aArray[$i][1] = FileGetTime($aArray[$i][0], $FT_MODIFIED, 1);$FT_STRING)
Next
; sort on times column
_ArraySort($aArray, 1, 0, 0, 1)
;_ArrayDisplay($aArray) ; check it
 MsgBox(0, "Newest Folder ", "Newest Folder Modified : " & $aArray[0][0])

 

Posted
Quote
1 hour ago, BrewManNH said:

FileGetTime returns an array by default, you need to use the format parameter to have it return a string to do what you're trying to do.

$FolderDate = FileGetTime($aArray[$i], $FT_MODIFIED, $FT_STRING)

 

 

I still got the same result :(

 

i dont know if the code is not working because of me not adding the arry display or sothing else 

Quote
1 hour ago, mikell said:

The regex check for backslash is useless,  _FileListToArray does it internally

#include <File.au3>
#include <Array.au3>

Global $spath = @desktopdir  ;"C:\T-in"

; list folders
$aArray = _FileListToArray($spath, "*", $FLTAR_FOLDERS)
; insert a column
_ArrayColInsert ($aArray, 1)
; populate new column with times
For $i = 1 to $aArray[0][0]
   $aArray[$i][1] = FileGetTime($aArray[$i][0], $FT_MODIFIED, 1);$FT_STRING)
Next
; sort on times column
_ArraySort($aArray, 1, 0, 0, 1)
;_ArrayDisplay($aArray) ; check it
 MsgBox(0, "Newest Folder ", "Newest Folder Modified : " & $aArray[0][0])

 

it just keep given me a random folder name who is not the newest folder in my selected path

am sorry if i could not understand some of your advice i hope you can find the answer for this and thanks for your help ^_^

Posted
Quote
1 hour ago, mikell said:

The regex check for backslash is useless,  _FileListToArray does it internally

#include <File.au3>
#include <Array.au3>

Global $spath = @desktopdir  ;"C:\T-in"

; list folders
$aArray = _FileListToArray($spath, "*", $FLTAR_FOLDERS)
; insert a column
_ArrayColInsert ($aArray, 1)
; populate new column with times
For $i = 1 to $aArray[0][0]
   $aArray[$i][1] = FileGetTime($aArray[$i][0], $FT_MODIFIED, 1);$FT_STRING)
Next
; sort on times column
_ArraySort($aArray, 1, 0, 0, 1)
;_ArrayDisplay($aArray) ; check it
 MsgBox(0, "Newest Folder ", "Newest Folder Modified : " & $aArray[0][0])

 

even if i use the _ArrayDisplay it still give list of random folders with no date order

:(

 

Posted

i have found a way to solve this thanks guys for your help ^^ that would have toke me days to notice but now i have another problem .

i have added another code to the script so when ever a folder is add in the selected path show it name 

#include <file.au3>
#include <array.au3>

Global $spath = ("C:\T-in")
$checkpath = StringRegExp($spath,"^.+\\$",0)
If $checkpath = 0 Then $spath = $spath & "\"

$aArray = _FileListToArray($spath,"*",$FLTAR_FOLDERS)

Func NewestFolder()

Global $aArray2D[10][2]
ReDim $aArray2D[$aArray[0]+1][2]
$aArray2D[0][0] = $aArray[0]

For $i=1 to $aArray[0]
    $aArray2D[$i][0] = $aArray[$i]
    $aArray2D[$i][1] = FileGetTime($spath & $aArray[$i],0,1)
Next
_ArraySort($aArray2D,1,1,"",1)
Global $newfolder = $aArray2D[1][0]
MsgBox(0, "", "a folder has been added .it name is :"& $newfolder)
EndFunc


While 1
While 2
$dnumX = DirGetSize($spath, 1)
    Sleep(500)
 $dnumY = DirGetSize($spath, 1)
If $dnumX[2] <> $dnumY[2] Then  NewestFolder()
     ExitLoop
WEnd

WEnd

thanks for your help ^^

Posted

this new code most call the name of the newest folder . but instead it calls the Folder that was befor the newest one and after that it keep calling it. the same folder again and again when ever a new folder is added 

Posted

i found the answer thanks to AutoBert

 

 it need to have the array inside the function

 

#include <file.au3>
#include <array.au3>

Global $spath = ("C:\T-in")
$checkpath = StringRegExp($spath,"^.+\\$",0)
If $checkpath = 0 Then $spath = $spath & "\"



Func NewestFolder()
$aArray = _FileListToArray($spath,"*",$FLTAR_FOLDERS)

Global $aArray2D[10][2]
ReDim $aArray2D[$aArray[0]+1][2]
$aArray2D[0][0] = $aArray[0]

For $i=1 to $aArray[0]
    $aArray2D[$i][0] = $aArray[$i]
    $aArray2D[$i][1] = FileGetTime($spath & $aArray[$i],0,1)
Next
_ArraySort($aArray2D,1,1,"",1)
Global $newfolder = $aArray2D[1][0]
MsgBox(0, "", "a folder has been added .it name is :"& $newfolder)
EndFunc


While 1
While 2
$dnumX = DirGetSize($spath, 1)
    Sleep(500)
 $dnumY = DirGetSize($spath, 1)
If $dnumX[2] <> $dnumY[2] Then  NewestFolder()
     ExitLoop
WEnd

WEnd

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