Achilles Posted September 23, 2008 Posted September 23, 2008 (edited) I decided that people (people being me) often open the file they last modified on their flashdrive when they reinsert their flashdrive at another later time. So I came up with this. It scans your whole drive and finds the file that was last modified. For it to work you'll need a file called autorun.inf in your immediate drive directory (i.e. E:\autorun.inf) that has this in it: [autorun] open=openlast.exe /autorunJust make a .txt file and rename it as an .inf. Then compile this as openlast.exe and place it in the same folder (i.e. E:\openlast.exe). Thanks to Smoke_N and simucal for their functions. Note: I haven't tested this much (for the date comparison part)... expandcollapse popup#include <Array.au3> Global $latest $temp = StringSplit(@ScriptDir, '\') $drive = $temp[1] & '\' $fileArray = _FileListToArrayEx($drive, '*.*', 1, '', True) If $fileArray = '' then Exit If $fileArray[0] = 1 then ShellExecute($fileArray[1]) EndIf $latest = _GetTimeArray(_GetExtProperty($fileArray[1], 3)) $latestFile = $fileArray[1] For $i = 1 to $fileArray[0] $array = _GetTimeArray(_GetExtProperty($fileArray[$i], 3)) If _LessThenLatest($array) then $latest = $array $latestFile = $fileArray[$i] EndIf Next If $latestFile <> @ScriptFullPath then $pass = Msgbox(36, 'Open File?', 'The last modified file on your drive was:' & @CRLF & $latestFile & @CRLF & 'Would you like to open this file?') If $pass = 6 then ShellExecute($latestFile) EndIf EndIf Func _LessThenLatest($array) If $array[0] < $latest[0] then Return False If $array[1] < $latest[1] then Return False If $array[2] < $latest[2] then Return False If $array[3] < $latest[3] then Return False If $array[4] < $latest[4] then Return False Return True EndFunc Func _GetTimeArray($string) Local $ret[5] ; Year ; Month ; Day ; Hour ; Minute $split = StringSplit($string, ' '); 9/21/2008 9:34 PM $splitDate = StringSplit($split[1], '/') $ret[0] = $splitDate[3] $ret[1] = $splitDate[1] $ret[2] = $splitDate[2] $splitTime = StringSplit($split[2], ':') If $split[3] = 'PM' then $splitTime[1] += 12 EndIf $ret[3] = $splitTime[1] $ret[4] = $splitTime[2] Return $ret EndFunc ;=============================================================================== ; ; Description: lists all or preferred files and or folders in a specified path (Similar to using Dir with the /B Switch) ; Syntax: _FileListToArrayEx($sPath, $sFilter = '*.*', $iFlag = 0, $sExclude = '') ; Parameter(s): $sPath = Path to generate filelist for ; $sFilter = The filter to use. Search the Autoit3 manual for the word "WildCards" For details, support now for multiple searches ; Example *.exe; *.txt will find all .exe and .txt files ; $iFlag = determines weather to return file or folders or both. ; $sExclude = exclude a file from the list by all or part of its name ; Example: Unins* will remove all files/folders that start with Unins ; $iFlag=0(Default) Return both files and folders ; $iFlag=1 Return files Only ; $iFlag=2 Return Folders Only ; ; Requirement(s): None ; Return Value(s): On Success - Returns an array containing the list of files and folders in the specified path ; On Failure - Returns the an empty string "" if no files are found and sets @Error on errors ; @Error or @extended = 1 Path not found or invalid ; @Error or @extended = 2 Invalid $sFilter or Invalid $sExclude ; @Error or @extended = 3 Invalid $iFlag ; @Error or @extended = 4 No File(s) Found ; ; Author(s): SmOke_N ; ; All files are written to a "reserved" .tmp file (Thanks to gafrost) for the example ; The Reserved file is then read into an array, then deleted ;=============================================================================== Func _FileListToArrayEx($sPath, $sFilter = '*.*', $iFlag = 0, $sExclude = '', $iRecurse = False) If Not FileExists($sPath) Then Return SetError(1, 1, '') If $sFilter = -1 Or $sFilter = Default Then $sFilter = '*.*' If $iFlag = -1 Or $iFlag = Default Then $iFlag = 0 If $sExclude = -1 Or $sExclude = Default Then $sExclude = '' Local $aBadChar[6] = ['\', '/', ':', '>', '<', '|'] $sFilter = StringRegExpReplace($sFilter, '\s*;\s*', ';') If StringRight($sPath, 1) <> '\' Then $sPath &= '\' For $iCC = 0 To 5 If StringInStr($sFilter, $aBadChar[$iCC]) Or _ StringInStr($sExclude, $aBadChar[$iCC]) Then Return SetError(2, 2, '') Next If StringStripWS($sFilter, 8) = '' Then Return SetError(2, 2, '') If Not ($iFlag = 0 Or $iFlag = 1 Or $iFlag = 2) Then Return SetError(3, 3, '') Local $oFSO = ObjCreate("Scripting.FileSystemObject"), $sTFolder $sTFolder = $oFSO.GetSpecialFolder(2) Local $hOutFile = @TempDir & $oFSO.GetTempName If Not StringInStr($sFilter, ';') Then $sFilter &= ';' Local $aSplit = StringSplit(StringStripWS($sFilter, 8), ';'), $sRead, $sHoldSplit For $iCC = 1 To $aSplit[0] If StringStripWS($aSplit[$iCC],8) = '' Then ContinueLoop If StringLeft($aSplit[$iCC], 1) = '.' And _ UBound(StringSplit($aSplit[$iCC], '.')) - 2 = 1 Then $aSplit[$iCC] = '*' & $aSplit[$iCC] $sHoldSplit &= '"' & $sPath & $aSplit[$iCC] & '" ' Next $sHoldSplit = StringTrimRight($sHoldSplit, 1) If $iRecurse Then RunWait(@Comspec & ' /c dir /b /s /a ' & $sHoldSplit & ' > "' & $hOutFile & '"', '', @SW_HIDE) Else RunWait(@ComSpec & ' /c dir /b /a ' & $sHoldSplit & ' /o-e /od > "' & $hOutFile & '"', '', @SW_HIDE) EndIf $sRead &= FileRead($hOutFile) If Not FileExists($hOutFile) Then Return SetError(4, 4, '') FileDelete($hOutFile) If StringStripWS($sRead, 8) = '' Then SetError(4, 4, '') Local $aFSplit = StringSplit(StringTrimRight(StringStripCR($sRead), 1), @LF) Local $sHold For $iCC = 1 To $aFSplit[0] If $sExclude And StringLeft($aFSplit[$iCC], _ StringLen(StringReplace($sExclude, '*', ''))) = StringReplace($sExclude, '*', '') Then ContinueLoop Switch $iFlag Case 0 If StringRegExp($aFSplit[$iCC], '\w:\\') = 0 Then $sHold &= $sPath & $aFSplit[$iCC] & Chr(1) Else $sHold &= $aFSplit[$iCC] & Chr(1) EndIf Case 1 If StringInStr(FileGetAttrib($sPath & '\' & $aFSplit[$iCC]), 'd') = 0 And _ StringInStr(FileGetAttrib($aFSplit[$iCC]), 'd') = 0 Then If StringRegExp($aFSplit[$iCC], '\w:\\') = 0 Then $sHold &= $sPath & $aFSplit[$iCC] & Chr(1) Else $sHold &= $aFSplit[$iCC] & Chr(1) EndIf EndIf Case 2 If StringInStr(FileGetAttrib($sPath & '\' & $aFSplit[$iCC]), 'd') Or _ StringInStr(FileGetAttrib($aFSplit[$iCC]), 'd') Then If StringRegExp($aFSplit[$iCC], '\w:\\') = 0 Then $sHold &= $sPath & $aFSplit[$iCC] & Chr(1) Else $sHold &= $aFSplit[$iCC] & Chr(1) EndIf EndIf EndSwitch Next If StringTrimRight($sHold, 1) Then Return StringSplit(StringTrimRight($sHold, 1), Chr(1)) Return SetError(4, 4, '') EndFunc;==> _FileListToArrayEx ;=============================================================================== ; Function Name: GetExtProperty($sPath,$iProp) ; Description: Returns an extended property of a given file. ; Return Value(s): On Success - The extended file property, or if $iProp = -1 then an array with all properties ; On Failure - 0, @Error - 1 (If file does not exist) ; Author(s): Simucal (Simucal@gmail.com) ; ;=============================================================================== Func _GetExtProperty($sPath, $iProp) Local $iExist, $sFile, $sDir, $oShellApp, $oDir, $oFile, $aProperty, $sProperty $iExist = FileExists($sPath) If $iExist = 0 Then SetError(1) Return 0 Else $sFile = StringTrimLeft($sPath, StringInStr($sPath, "\", 0, -1)) $sDir = StringTrimRight($sPath, (StringLen($sPath) - StringInStr($sPath, "\", 0, -1))) $oShellApp = ObjCreate ("shell.application") $oDir = $oShellApp.NameSpace ($sDir) $oFile = $oDir.Parsename ($sFile) If $iProp = -1 Then Local $aProperty[35] For $i = 0 To 34 $aProperty[$i] = $oDir.GetDetailsOf ($oFile, $i) Next Return $aProperty Else $sProperty = $oDir.GetDetailsOf ($oFile, $iProp) If $sProperty = "" Then Return 0 Else Return $sProperty EndIf EndIf EndIf EndFunc;==> _GetExtProperty Edited September 23, 2008 by Achilles My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
peppercorngiant Posted September 23, 2008 Posted September 23, 2008 This will be very useful, I will give it a go on my 8gb flashdrive to test the speed. Thanks [font="Lucida Console"]The truth is out there[/font]
Achilles Posted September 23, 2008 Author Posted September 23, 2008 This will be very useful, I will give it a go on my 8gb flashdrive to test the speed. ThanksI've been thinking that I could actually develop this into a bigger thing. Here's some thoughts for the future:Change desktop background to the on you have on your flash and restore the original when you're doneCustimize firefox bookmarks and then replace them with the original when you're done with using your driveUsing KMP as a media player and play songs on flashdrive - I might do thisOpen last modified file - It already does this My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
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