grimmlock Posted February 25, 2013 Posted February 25, 2013 Good Morning, I modified this code that I found on Autoit forums to display the information that I need, however there is one thing that I would like help with. Is there a way to modify this, so that the code looks at all the files inside "folder2" and then have $b display the date of the most recently modified file? Here is the code I have... Local $a = FileGetTime("C:\folder1\folder\testing1.txt", 0) Local $b = FileGetTime("C:\folder1\folder2", 0) local $c = FileGetTime("C:\folder1\folder3\testing2.txt", 0) Local $atd = $a[1] & "/" & $a[2] & "/" & $a[0] Local $btd = $b[1] & "/" & $b[2] & "/" & $b[0] Local $ctd = $c[1] & "/" & $c[2] & "/" & $c[0] If MsgBox(4, "Creation date of ...", "Update Files?" & @CRLF & @CRLF & "file1" & " -- " & $atd & @CRLF & @CRLF & "folder1" & " -- " & $btd & @CRLF & @CRLF & "file2" & " -- " & $ctd) = 6 Then _Copying() EndIf Thanks Grimm Thanks Grimm
iamtheky Posted February 25, 2013 Posted February 25, 2013 (edited) #include <File.au3> Local $a = FileGetTime("C:\folder1\folder\testing1.txt", 0) $last = 0 $sFolder = "C:\folder1\folder2" If @Error = 1 Then exit $aFiles = _FileListToArray($sFolder , "*" , 1) for $i = 1 to $aFiles[0] $time = filegettime($sFolder & "\" & $aFiles[$i] , 0 , 1) If $time > $last Then $b = $aFiles[$I] & " modified: " & $time $last = $time EndIf next msgbox (0 , '' , $b) local $c = FileGetTime("C:\folder1\folder3\testing2.txt", 0) Local $atd = $a[1] & "/" & $a[2] & "/" & $a[0] Local $btd = $b[1] & "/" & $b[2] & "/" & $b[0] Local $ctd = $c[1] & "/" & $c[2] & "/" & $c[0] If MsgBox(4, "Creation date of ...", "Update Files?" & @CRLF & @CRLF & "file1" & " -- " & $atd & @CRLF & @CRLF & "folder1" & " -- " & $btd & @CRLF & @CRLF & "file2" & " -- " & $ctd) = 6 Then _Copying() [size=4]EndIf[/size] Edited February 25, 2013 by boththose ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
grimmlock Posted February 25, 2013 Author Posted February 25, 2013 (edited) Thank you boththose, I just have1 error and 1 question. I get this error after the msgbox (0, '', $b:) Local $btd = $b[1] & "/" & $b[2] & "/" & $b[0] Local $btd = $b^ ERROR Error: Subscript used with non-array variable. Question: How do I adjust the time / date for $b to display just the month/day/year? Thanks Grimm Edited February 25, 2013 by grimmlock Thanks Grimm
iamtheky Posted February 25, 2013 Posted February 25, 2013 (edited) sorry i just copied all your stuff back blindly, here it is by itself #include <File.au3> $last = 0 $sFolder = "C:\folder1\folder2" If @Error = 1 Then exit $aFiles = _FileListToArray($sFolder , "*" , 1) for $i = 1 to $aFiles[0] $time = filegettime($sFolder & "\" & $aFiles[$i] , 0 , 1) If $time > $last Then $newfile = $aFiles[$I] $last = $time EndIf next $b = filegettime($sFolder & "\" & $newfile) Local $btd = $b[1] & "/" & $b[2] & "/" & $b[0] msgbox(0, '' , $btd) Edited February 25, 2013 by boththose ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
grimmlock Posted February 25, 2013 Author Posted February 25, 2013 Thank you boththose, you rock Grimm Thanks Grimm
grimmlock Posted April 15, 2013 Author Posted April 15, 2013 (edited) For some reason this works on my computer but no one elses expandcollapse popup#include <File.au3> Local $a = FileGetTime("\\192.168.26.17\it\My Scripting Workshop\My Utility\ADStaff\staff.txt", 0) $last = 0 $sFolder = "\\192.168.26.17\it\My Scripting Workshop\My Utility\DHCP" If @Error = 1 Then exit $aFiles = _FileListToArray($sFolder , "*" , 1) for $i = 1 to $aFiles[0] $time = filegettime($sFolder & "\" & $aFiles[$i] , 0 , 1) If $time > $last Then $b = $aFiles[$I] & " modified: " & $time $last = $time EndIf next msgbox (0 , '' , $b) ;============================= Local $c = FileGetTime("C:\Program Files\My Utility\ADStaff\staff.txt", 0) $last = 0 $sFolder = "C:\Program Files\My Utility\DHCP" If @Error = 1 Then exit $aFiles = _FileListToArray($sFolder , "*" , 1) for $i = 1 to $aFiles[0] $time = filegettime($sFolder & "\" & $aFiles[$i] , 0 , 1) If $time > $last Then $d = $aFiles[$I] & " modified: " & $time $last = $time EndIf next msgbox (0 , '' , $d) Local $atd = $a[1] & "/" & $a[2] & "/" & $a[0] Local $btd = $b[1] & "/" & $b[2] & "/" & $b[0] Local $ctd = $c[1] & "/" & $c[2] & "/" & $c[0] Local $dtd = $d[1] & "/" & $d[2] & "/" & $d[0] MsgBox(0, "Creation date of ...", "server" & $atd & $btd & @CRLF & @CRLF & $ctd & $dtd) Thanks Grimm Edited April 15, 2013 by grimmlock Thanks Grimm
iamtheky Posted April 15, 2013 Posted April 15, 2013 Where does it fail? right at the start? does $a return anything? ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
grimmlock Posted April 15, 2013 Author Posted April 15, 2013 If I run it ... using the editor no errors show up. And if I simply run it normally by right clicking on the script and clicking on Run Script nothing happens. I can see, using Task Manager, that something tries to run, but then it just disappears from Task Manager, which means, I assume, it ran successfully however the msgbox never shows up. I have tried to get results from doing a msgbox(0, '', $a) and nothing shows up. Thanks Grimm Thanks Grimm
kylomas Posted April 15, 2013 Posted April 15, 2013 grimmlock, Just offering another alternative. This creates a temp file of all files modified after a date you specify in the named directory and all sub-directories. expandcollapse popup#include <file.au3> local $compdate = '20130220' ; list any files modified after this date local $dir = 'k:\autoit\' ; this directory and all subdirectories local $aDir = dirgetsize($dir,1), $st = timerinit(), $sPString ConsoleWrite('Running ' & $aDir[1] & ' files' & @LF) local $fl = _TempFile(default,default,'.txt') filewrite( $fl,do_files($dir) ) ConsoleWrite('Time for complete process = ' & round(timerdiff($st)/1000,4) & ' seconds' & @LF) shellexecutewait($fl) filedelete($fl) func do_files($sdir) if stringright($sdir,1) <> '\' then $sdir &= '\' local $files = filefindfirstfile($sdir & '*.*') if $files = -1 then $sPString &= stringformat( '%-100s %-30s \n', $sdir, 'No files found' ) return endif while 1 $file = filefindnextfile($files) if @error then exitloop if @extended then do_files($sdir & $file) if stringleft(filegettime($sdir & $file,0,1),8) > $compdate then $sPString &= stringformat( '%-100s %-30s \n',$sdir & $file, filegettime($sdir & $file,0,1) ) WEnd return $sPString endfunc kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
grimmlock Posted April 16, 2013 Author Posted April 16, 2013 So I started from scratch and by adding the DriveMapAdd I was able to get better output. However now, the error is with this line "Autoit Error Line 48: Local $btd = $b[1] & "/" & $b[2] & "/" & $b[0] Local $btb = $b^error Error: Subscript used with non-array variable." Any ideas? Below is the code expandcollapse popup#include <file.au3> DriveMapAdd("y:", "\\192.168.26.17\IT") ;~ Sleep(1000) Local $a = FileGetTime("y:\My Scripting Workshop\My Utility\ADStaff\staff.txt", 0) $last = 0 $sFolder = "y:My Scripting Workshop\My Utility\DHCP" If @Error = 1 Then exit $aFiles = _FileListToArray($sFolder , "*" , 1) for $i = 1 to $aFiles[0] $time = filegettime($sFolder & "\" & $aFiles[$i] , 0 , 1) If $time > $last Then $b = $aFiles[$I] & " modified: " & $time $last = $time EndIf next ;~ msgbox (0 , '' , $b) Local $c = FileGetTime("C:\Program Files\My Utility\ADStaff\staff.txt", 0) $hlast = 0 $hFolder = "C:\Program Files\My Utility\DHCP" If @Error = 1 Then exit $hFiles = _FileListToArray($hFolder , "*" , 1) for $i = 1 to $hFiles[0] $htime = filegettime($hFolder & "\" & $hFiles[$i] , 0 , 1) If $htime > $hlast Then $d = $hFiles[$I] & " modified: " & $htime $hlast = $htime EndIf next msgbox (0 , '' , $d) Local $atd = $a[1] & "/" & $a[2] & "/" & $a[0] Local $btd = $b[1] & "/" & $b[2] & "/" & $b[0] Local $ctd = $c[1] & "/" & $c[2] & "/" & $c[0] ;~Local $dtd = $d[1] & "/" & $d[2] & "/" & $d[0] MsgBox(0, "Creation date of ...", "server" & @CRLF & @CRLF & $atd & " ----- " & $ctd) Thanks! Grimm Thanks Grimm
BrewManNH Posted April 16, 2013 Posted April 16, 2013 $b is a simple variable, it's not an array in your script. That's why you get the error. 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 GudeHow 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
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