bubke Posted October 26, 2010 Share Posted October 26, 2010 Is there someone who can help me with sorting directories on timestamp in an array. For example if I only want the directories and files what are one month old. Thanks. Link to comment Share on other sites More sharing options...
iamtheky Posted October 26, 2010 Share Posted October 26, 2010 (edited) Heres how you can sort em expandcollapse popup#include <array.au3> $files = recursivefilesearch ("C:\windows\system32") _arraydelete ($files , 0) _arraysort($files) _arraydisplay ($files) ;;;:::::WEAPON X's - RECURSIVE FILE SEARCH - PULLS FULL DIRECTORY AND NAME::::::::::::::::::::::::::: Func RecursiveFileSearch ($startDir, $depth = 0) If $depth = 0 Then Global $RFSstring = "" $search = FileFindFirstFile($startDir & "\*.*") If @error Then Return ;Search through all files and folders in directory While 1 $next = FileFindNextFile($search) If @error Then ExitLoop ;If folder, recurse If StringInStr(FileGetAttrib($startDir & "\" & $next), "D") Then $time = filegettime ($startDir & "\" & $next, 0 , 1) $RFSstring &= $time & " ----- " & $startDir & "\" & $next & "*" RecursiveFileSearch ($startDir & "\" & $next, $depth + 1) Else ;Append filename to master string $time = filegettime ($startDir & "\" & $next, 0 , 1) $RFSstring &= $time & " ----- " & $startDir & "\" & $next & "*" EndIf WEnd FileClose($search) If $depth = 0 Then Return (StringSplit(StringTrimRight($RFSstring, 1), "*")) EndFunc ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;==>RecursiveFileSearch Scrubbed for everything from september forward:: #include <array.au3> $files = recursivefilesearch ("C:\windows\system32") _arraydelete ($files , 0) _arraysort($files) _arraydisplay ($files) ;;;:::::WEAPON X's - RECURSIVE FILE SEARCH - PULLS FULL DIRECTORY AND NAME::::::::::::::::::::::::::: Func RecursiveFileSearch ($startDir, $depth = 0) If $depth = 0 Then Global $RFSstring = "" $search = FileFindFirstFile($startDir & "\*.*") If @error Then Return ;Search through all files and folders in directory While 1 $next = FileFindNextFile($search) If @error Then ExitLoop ;If folder, recurse If StringInStr(FileGetAttrib($startDir & "\" & $next), "D") Then $time = filegettime ($startDir & "\" & $next, 0 , 1) If $time > 20100901000000 Then $RFSstring &= $time & " ----- " & $startDir & "\" & $next & "*" RecursiveFileSearch ($startDir & "\" & $next, $depth + 1) Endif Else ;Append filename to master string $time = filegettime ($startDir & "\" & $next, 0 , 1) If $time > 20100901000000 Then $RFSstring &= $time & " ----- " & $startDir & "\" & $next & "*" Endif EndIf WEnd FileClose($search) If $depth = 0 Then Return (StringSplit(StringTrimRight($RFSstring, 1), "*")) EndFunc ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;==>RecursiveFileSearch Edited October 26, 2010 by iamtheky ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
bubke Posted October 26, 2010 Author Share Posted October 26, 2010 Heres how you can sort em expandcollapse popup#include <array.au3> $files = recursivefilesearch ("C:\windows\system32") _arraydelete ($files , 0) _arraysort($files) _arraydisplay ($files) ;;;:::::WEAPON X's - RECURSIVE FILE SEARCH - PULLS FULL DIRECTORY AND NAME::::::::::::::::::::::::::: Func RecursiveFileSearch ($startDir, $depth = 0) If $depth = 0 Then Global $RFSstring = "" $search = FileFindFirstFile($startDir & "\*.*") If @error Then Return ;Search through all files and folders in directory While 1 $next = FileFindNextFile($search) If @error Then ExitLoop ;If folder, recurse If StringInStr(FileGetAttrib($startDir & "\" & $next), "D") Then $time = filegettime ($startDir & "\" & $next, 0 , 1) $RFSstring &= $time & " ----- " & $startDir & "\" & $next & "*" RecursiveFileSearch ($startDir & "\" & $next, $depth + 1) Else ;Append filename to master string $time = filegettime ($startDir & "\" & $next, 0 , 1) $RFSstring &= $time & " ----- " & $startDir & "\" & $next & "*" EndIf WEnd FileClose($search) If $depth = 0 Then Return (StringSplit(StringTrimRight($RFSstring, 1), "*")) EndFunc ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;==>RecursiveFileSearch Scrubbed for everything from september forward:: #include <array.au3> $files = recursivefilesearch ("C:\windows\system32") _arraydelete ($files , 0) _arraysort($files) _arraydisplay ($files) ;;;:::::WEAPON X's - RECURSIVE FILE SEARCH - PULLS FULL DIRECTORY AND NAME::::::::::::::::::::::::::: Func RecursiveFileSearch ($startDir, $depth = 0) If $depth = 0 Then Global $RFSstring = "" $search = FileFindFirstFile($startDir & "\*.*") If @error Then Return ;Search through all files and folders in directory While 1 $next = FileFindNextFile($search) If @error Then ExitLoop ;If folder, recurse If StringInStr(FileGetAttrib($startDir & "\" & $next), "D") Then $time = filegettime ($startDir & "\" & $next, 0 , 1) If $time > 20100901000000 Then $RFSstring &= $time & " ----- " & $startDir & "\" & $next & "*" RecursiveFileSearch ($startDir & "\" & $next, $depth + 1) Endif Else ;Append filename to master string $time = filegettime ($startDir & "\" & $next, 0 , 1) If $time > 20100901000000 Then $RFSstring &= $time & " ----- " & $startDir & "\" & $next & "*" Endif EndIf WEnd FileClose($search) If $depth = 0 Then Return (StringSplit(StringTrimRight($RFSstring, 1), "*")) EndFunc ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;==>RecursiveFileSearch Thank you for your quick reaction. Your script is almost good, but it is not necesary to search in directories, I need only the directories in one map in the array, not the files in it. I want to copy only the directories which are not older then one month to another directory. Also the files in root of the map must be filtert and copy to that same directory where the directories are copied. I can't figure it out. I hope you can help me with this. Thanks! 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