Jump to content

Recommended Posts

I've encountered a problem with a single file where I cannot retrieve it's Date-time. So far my code has worked well for over 30 files, but this one is a mystery I cannot debug myself due to insufficient Au3 knowledge.

In line 11 "_Date_Time_FileTimeToArray" is called and for this particular file it sets the @error to 10. I don't know what that error code means, but it's not set by the _Date functions themselves I think.

Overall, it could be a problem caused by any of the functions below, how can I properly debug this? / Does anybody know a what's causing this?

_WinAPI_CreateFile() / _Date_Time_GetFileTime() / _Date_Time_FileTimeToArray()

Func _SetFileTimes($sFilePath)
    Local $monthNumber[13] = ["", "January", "February", "March", "April", "May", "Juny", "July", "August", "September", "October", "November", "December"]
    Local $dayNumber[7] = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
    
    Local $fHandle = _WinAPI_CreateFile($sFilePath, 2, 2) ; read-only
    ; may NOT return a valid date for some reason! TODO
    Local $fTagFILETIME = _Date_Time_GetFileTime($fHandle)
    _WinAPI_CloseHandle($fHandle)
    
    ; This will return an empty array if theres no valid date
    $fModTime = _Date_Time_FileTimeToArray($fTagFILETIME[2]) ; last Modified
    if @error <> 10 then
        Local $year = $fModTime[2]
        Local $month = $fModTime[0]
        Local $day = $fModTime[1]
        Local $hour = $fModTime[3]
        Local $min = $fModTime[4]
        Local $sec = $fModTime[5]
        Local $ms = $fModTime[6]
        Local $weekday = $fModTime[7]
        
        Global $prettyTimestamp = StringFormat("%s, %s %d, %04d %02d:%02d:%02d", $dayNumber[$weekday], $monthNumber[$month], $day, $year, $hour, $min, $sec)
        Global $uploadDate = StringFormat("%04d-%02d-%02d", $year, $month, $day)
        
        $fModTime = _Date_Time_FileTimeToArray(_Date_Time_FileTimeToLocalFileTime($fTagFILETIME[2])) ; last Modified
        Local $year = $fModTime[2]
        Local $month = $fModTime[0]
        Local $day = $fModTime[1]
        Local $hour = $fModTime[3]
        Local $min = $fModTime[4]
        Local $sec = $fModTime[5]
        Local $ms = $fModTime[6]
        Local $weekday = $fModTime[7]
        
        ; GetUnixTime accounts for Local time, hence feed it local time
        Global $unixTimestamp = _GetUnixTime($year &"/"& $month &"/"& $day &" "& $hour&":"& $min &":"& $sec)
    else
        Global $prettyTimestamp = "N/A"
        Global $uploadDate = ""
        Global $unixTimestamp = "N/A"
    endif
    
    
endfunc

 

_GetUnixTime returned the year 1601 start date, showing that $fModTime is probably equal 0. (But Why?)

The file reports these dates in Explorer, it's on local NTFS drive:

Created: ‎‎Wednesday, ‎31. ‎Januar ‎2018, ‏‎18:55:02

Modified: ‎Wednesday, ‎10. ‎Januar ‎2018, ‏‎12:39:23

Accessed: ‎Wednesday, ‎10. ‎Januar ‎2018, ‏‎12:39:23

Share this post


Link to post
Share on other sites

Try FileGetTime.

Other than that, the file is in use by some program that locks it or something, or is in read mode.

Dont see other options. Maybe a bug.


Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Share this post


Link to post
Share on other sites

I don't know it help help for you or not:

#include <WinAPIFiles.au3>
#include <WinAPIHObj.au3>
#include <Date.au3>
#include <FileConstants.au3>

Global $iFileToWork = @ScriptFullPath

FileSetTime($iFileToWork, @YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC, $FT_CREATED)
FileSetTime($iFileToWork, @YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC, $FT_MODIFIED)
FileSetTime($iFileToWork, @YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC, $FT_ACCESSED)

_FileGetTime($iFileToWork)


Func _FileGetTime($sFilePath)

    Local $Created_ArrayFileTime = FileGetTime($sFilePath, $FT_CREATED) ;  $FT_CREATED (1) = Created
    Local $Created_iYear = $Created_ArrayFileTime[0] ; = year (four digits)
    Local $Created_iMonth = $Created_ArrayFileTime[1] ; = month (range 01 - 12)
    Local $Created_iDay = $Created_ArrayFileTime[2] ; = day (range 01 - 31)
    Local $Created_iHour = $Created_ArrayFileTime[3] ; = hour (range 00 - 23)
    Local $Created_iMin = $Created_ArrayFileTime[4] ; = min (range 00 - 59)
    Local $Created_iSec = $Created_ArrayFileTime[5] ; = sec (range 00 - 59)
    Local $Created_iDayOfWeek = _DateToDayOfWeek($Created_iYear, $Created_iMonth, $Created_iDay)
    Local $Created_iDayName = _DateDayOfWeek($Created_iDayOfWeek)
    Local $Created_iMonthName = _DateToMonth($Created_iMonth)
    Local $Created_iShortTime = $Created_iYear & $Created_iMonth & $Created_iDay & $Created_iHour & $Created_iMin & $Created_iSec
    Local $Created_iLongTime = $Created_iYear & "/" & $Created_iMonth & "/" & $Created_iDay & " - " & $Created_iHour & ":" & $Created_iMin & ":" & $Created_iSec
    Local $Created_iLongTimeName = $Created_iDayName & "," & $Created_iMonthName & " " & $Created_iDay & "," & $Created_iYear
    ConsoleWrite("! File   : " & $sFilePath & @CRLF)
    ConsoleWrite("-DATE Created  : " & $Created_iLongTimeName & @CRLF)
    ConsoleWrite(">DATE Created S: " & $Created_iLongTime & @CRLF)
    ConsoleWrite("+DATE Created L: " & $Created_iShortTime & @CRLF)
    ConsoleWrite("-Year     : " & $Created_iYear & @CRLF)
    ConsoleWrite("-Mont     : " & $Created_iMonth & @CRLF)
    ConsoleWrite("-Day      : " & $Created_iDay & @CRLF)
    ConsoleWrite("-Hour     : " & $Created_iHour & @CRLF)
    ConsoleWrite("-Min      : " & $Created_iMin & @CRLF)
    ConsoleWrite("-Sec      : " & $Created_iSec & @CRLF)
    ConsoleWrite("-DayOfWeek: " & $Created_iDayOfWeek & @CRLF)
    ConsoleWrite("-DayName  : " & $Created_iDayName & @CRLF)
    ConsoleWrite("-MonthName: " & $Created_iMonthName & @CRLF)

    Local $Modified_ArrayFileTime = FileGetTime($sFilePath, $FT_MODIFIED) ;$FT_MODIFIED (0) = Last modified
    Local $Modified_iYear = $Modified_ArrayFileTime[0] ; = year (four digits)
    Local $Modified_iMonth = $Modified_ArrayFileTime[1] ; = month (range 01 - 12)
    Local $Modified_iDay = $Modified_ArrayFileTime[2] ; = day (range 01 - 31)
    Local $Modified_iHour = $Modified_ArrayFileTime[3] ; = hour (range 00 - 23)
    Local $Modified_iMin = $Modified_ArrayFileTime[4] ; = min (range 00 - 59)
    Local $Modified_iSec = $Modified_ArrayFileTime[5] ; = sec (range 00 - 59)
    Local $Modified_iDayOfWeek = _DateToDayOfWeek($Modified_iYear, $Modified_iMonth, $Modified_iDay)
    Local $Modified_iDayName = _DateDayOfWeek($Modified_iDayOfWeek)
    Local $Modified_iMonthName = _DateToMonth($Modified_iMonth)
    Local $Modified_iShortTime = $Modified_iYear & $Modified_iMonth & $Modified_iDay & $Modified_iHour & $Modified_iMin & $Modified_iSec
    Local $Modified_iLongTime = $Modified_iYear & "/" & $Modified_iMonth & "/" & $Modified_iDay & " - " & $Modified_iHour & ":" & $Modified_iMin & ":" & $Modified_iSec
    Local $Modified_iLongTimeName = $Modified_iDayName & "," & $Modified_iMonthName & " " & $Modified_iDay & "," & $Modified_iYear
    ConsoleWrite("! File   : " & $sFilePath & @CRLF)
    ConsoleWrite("-DATE Modified  : " & $Modified_iLongTimeName & @CRLF)
    ConsoleWrite(">DATE Modified S: " & $Modified_iLongTime & @CRLF)
    ConsoleWrite("+DATE Modified L: " & $Modified_iShortTime & @CRLF)
    ConsoleWrite("-Year     : " & $Modified_iYear & @CRLF)
    ConsoleWrite("-Mont     : " & $Modified_iMonth & @CRLF)
    ConsoleWrite("-Day      : " & $Modified_iDay & @CRLF)
    ConsoleWrite("-Hour     : " & $Modified_iHour & @CRLF)
    ConsoleWrite("-Min      : " & $Modified_iMin & @CRLF)
    ConsoleWrite("-Sec      : " & $Modified_iSec & @CRLF)
    ConsoleWrite("-DayOfWeek: " & $Modified_iDayOfWeek & @CRLF)
    ConsoleWrite("-DayName  : " & $Modified_iDayName & @CRLF)
    ConsoleWrite("-MonthName: " & $Modified_iMonthName & @CRLF)

    Local $Accessed_ArrayFileTime = FileGetTime($sFilePath, $FT_ACCESSED) ; $FT_ACCESSED (2) = Last accessed
    Local $Accessed_iYear = $Accessed_ArrayFileTime[0] ; = year (four digits)
    Local $Accessed_iMonth = $Accessed_ArrayFileTime[1] ; = month (range 01 - 12)
    Local $Accessed_iDay = $Accessed_ArrayFileTime[2] ; = day (range 01 - 31)
    Local $Accessed_iHour = $Accessed_ArrayFileTime[3] ; = hour (range 00 - 23)
    Local $Accessed_iMin = $Accessed_ArrayFileTime[4] ; = min (range 00 - 59)
    Local $Accessed_iSec = $Accessed_ArrayFileTime[5] ; = sec (range 00 - 59)
    Local $Accessed_iDayOfWeek = _DateToDayOfWeek($Accessed_iYear, $Accessed_iMonth, $Accessed_iDay)
    Local $Accessed_iDayName = _DateDayOfWeek($Accessed_iDayOfWeek)
    Local $Accessed_iMonthName = _DateToMonth($Accessed_iMonth)
    Local $Accessed_iShortTime = $Accessed_iYear & $Accessed_iMonth & $Accessed_iDay & $Accessed_iHour & $Accessed_iMin & $Accessed_iSec
    Local $Accessed_iLongTime = $Accessed_iYear & "/" & $Accessed_iMonth & "/" & $Accessed_iDay & " - " & $Accessed_iHour & ":" & $Accessed_iMin & ":" & $Accessed_iSec
    Local $Accessed_iLongTimeName = $Accessed_iDayName & "," & $Accessed_iMonthName & " " & $Accessed_iDay & "," & $Accessed_iYear
    ConsoleWrite("! File   : " & $sFilePath & @CRLF)
    ConsoleWrite("-DATE Accessed  : " & $Accessed_iLongTimeName & @CRLF)
    ConsoleWrite(">DATE Accessed S: " & $Accessed_iLongTime & @CRLF)
    ConsoleWrite("+DATE Accessed L: " & $Accessed_iShortTime & @CRLF)
    ConsoleWrite("-Year     : " & $Accessed_iYear & @CRLF)
    ConsoleWrite("-Mont     : " & $Accessed_iMonth & @CRLF)
    ConsoleWrite("-Day      : " & $Accessed_iDay & @CRLF)
    ConsoleWrite("-Hour     : " & $Accessed_iHour & @CRLF)
    ConsoleWrite("-Min      : " & $Accessed_iMin & @CRLF)
    ConsoleWrite("-Sec      : " & $Accessed_iSec & @CRLF)
    ConsoleWrite("-DayOfWeek: " & $Accessed_iDayOfWeek & @CRLF)
    ConsoleWrite("-DayName  : " & $Accessed_iDayName & @CRLF)
    ConsoleWrite("-MonthName: " & $Accessed_iMonthName & @CRLF)

    
EndFunc   ;==>_FileGetTime

 

Share this post


Link to post
Share on other sites

Thanks guys for the answers, took me too long to notice because I was supposed to be notified by email.

I was going to test VIP's code to debug, but the problem has somehow resolved itself. The exact same code of mine now returns the correct date and parses it without problems... A very strange edge-case. I don't think it was a lock problem like careca said, because these files shouldn't have been accessed by any programs and my tool opened them in read-mode anyway (to fetch the date).

In any way, I developed the code above in one go without reboots, maybe that fixed it. Windows 7 SP1 64-bit, NTFS. /thread

Share this post


Link to post
Share on other sites
Posted (edited)
On 11/11/2018 at 7:19 PM, careca said:

Other than that, the file is in use by some program that locks it or something, or is in read mode.

Solved the mystery:

As careca said, THE FILE WAS LOCKED. Although I opened the file in READ-ONLY in my code and the file was also opened READ-ONLY by MediaPlayerClassic -  apparently it was enough for Windows to deny file access to my AutoIt script... Damn!

I also found out why:

The _WinAPI_CreateFile() doc states: _WinAPI_CreateFile ( $sFileName, $iCreation [, $iAccess = 4 [, $iShare = 0 [, $iAttributes = 0 [, $tSecurity = 0]]]] )

Local $fHandle = _WinAPI_CreateFile($sFilePath, 2, 2) ; read-only

Do you see it? Although I opened the file as read-only, the DEFAULT $iShare access in Au3 is set to NOT SHARE (==0).

Quote
$iShare [optional] Sharing mode of an object:
    1 - Delete
    2 - Read
    4 - Write

So if you open the file in really read-only, to get it's metadata, you want to allow ANY kind of access. Be it another read-only, write or delete:

Local $fHandle = _WinAPI_CreateFile($sFilePath, 2, 2, 7) ; read-only and share any

Now the file can be opened by my media player and I can retrieve its metadata in background! I didn't know a read-only access had to be allowed in the API call, I just assumed it by default.

Edited by VADemon

Share this post


Link to post
Share on other sites

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

  • Similar Content

    • By Scriptmaster
      <NEWBIE ALERT>
      Is it possible to unzip a zip file in Autoit without using a dll!
      My script downloads a zip file to a temporary directory (successfully) and it must be unzipped to (Or moved to after unzip) another a folder which just happens to be
      @scriptdir & "file.exe" Thanks in advance
    • By Inpho
      Hi All,
      I intend on keeping custom functions/UDFs (works in progress) here; if anyone wants to use any code, feel free.
      String functions:
      #AutoIt3Wrapper_AU3Check_Parameters=-d -w- 1 -w 2 -w 3 -w 4 -w 5 -w 6 #include-once ; #FUNCTION# ==================================================================================================================== ; Name ..........: _DateTimeGet ; Description ...: Returns the date and time formatted for use in sortable filenames, logs, listviews, etc. ; Syntax ........: _DateTimeGet(iType = 1[, $bHumanFormat = False]) ; Parameters ....: $iType - [optional] an integer value. Default is 1. ; 1 - Date and time in file-friendly format; 20190115_113756 ; 2 - Date in file-friendly format; 20190115 ; 3 - Time in file friendly format; 113756 ; $bHumanFormat - [optional] a boolean value. Default is False. ; True - Includes slashes in the date and colons in the time with a space inbetween ; False - No slashes or colons included with an underscore inbetween ; Return values .: Success - String ; Failure - Sets @error to non-zero and returns an empty string ; Author ........: Sam Coates ; =============================================================================================================================== Func _DateTimeGet($iType = 1, $bHumanFormat = False) If $iType < 1 Or $iType > 3 Then Return (SetError(-1, 0, "")) ;; Param1: ;; 1 = Date and time in file friendly format: 20190115_113756 ;; 2 = Date in file friendly format: 20190115 ;; 3 = Time in file friendly format: 113756 ;; Param2: ;; True = Use human-readable format: 15/01/2019 11:37:56 Local $sTime = @HOUR & ":" & @MIN & ":" & @SEC Local $sDate = @MDAY & "/" & @MON & "/" & @YEAR If $iType = 1 Then If $bHumanFormat = False Then $sTime = StringReplace($sTime, ":", "") $sDate = StringReplace($sDate, "/", "") $sDate = StringTrimLeft($sDate, 4) & StringMid($sDate, 3, 2) & StringLeft($sDate, 2) Return ($sDate & "_" & $sTime) Else Return ($sDate & " " & $sTime) EndIf ElseIf $iType = 2 Then If $bHumanFormat = False Then $sDate = StringReplace($sDate, "/", "") $sDate = StringTrimLeft($sDate, 4) & StringMid($sDate, 3, 2) & StringLeft($sDate, 2) EndIf Return ($sDate) ElseIf $iType = 3 Then If $bHumanFormat = False Then $sTime = StringReplace($sTime, "/", "") EndIf Return ($sTime) EndIf EndFunc ;==>_DateTimeGet ; #FUNCTION# ==================================================================================================================== ; Name ..........: _FileToFileExtension ; Description ...: Returns a file extension from a filename/FQPN (Fully Qualified Path Name) ; Syntax ........: _FileToFileExtension($sPath) ; Parameters ....: $sPath - a string value. ; Return values .: Success - String ; Failure - Empty string as returned from StringTrimLeft() ; Author ........: Sam Coates ; =============================================================================================================================== Func _FileToFileExtension($sPath) Return (StringTrimLeft($sPath, StringInStr($sPath, ".", 0, -1))) EndFunc ;==>_FileToFileExtension ; #FUNCTION# ==================================================================================================================== ; Name ..........: _FileToFileName ; Description ...: Returns a filename from a FQPN (Fully Qualified Path Name) ; Syntax ........: _FileToFileName($sPath[, $bIncludeExtension = True]) ; Parameters ....: $sPath - a string value. ; $bIncludeExtension - [optional] a boolean value. Default is True. ; Return values .: Success - String ; Failure - Empty string as returned from StringLeft() ; Author ........: Sam Coates ; =============================================================================================================================== Func _FileToFileName($sPath, $bIncludeExtension = True) Local $sReturn = StringTrimLeft($sPath, StringInStr($sPath, "\", 0, -1)) If $bIncludeExtension = False Then $sReturn = StringLeft($sReturn, StringInStr($sReturn, ".", 0, -1) - 1) Return ($sReturn) EndFunc ;==>_FileToFileName ; #FUNCTION# ==================================================================================================================== ; Name ..........: _FileToFilePath ; Description ...: Returns a folder path from a FQPN (Fully Qualified Path Name) ; Syntax ........: _FileToFilePath($sPath) ; Parameters ....: $sPath - a string value. ; Return values .: Success - String ; Failure - Empty string as returned from StringLeft() ; Author ........: Sam Coates ; =============================================================================================================================== Func _FileToFilePath($sPath) Return (StringLeft($sPath, StringInStr($sPath, "\", 0, -1) - 1)) EndFunc ;==>_FileToFilePath ; #FUNCTION# ==================================================================================================================== ; Name ..........: _StringLeft ; Description ...: Searches for a string inside a string, then removes everything on the right of that string ; Syntax ........: _StringLeft($sString, $sRemove[, $iCaseSense = 0, $iOccurrence = 1]) ; Parameters ....: $sString - a string value. The string to search inside. ; $sRemove - a string value. The string to search for. ; $iCaseSense - an integer value. Flag to indicate if the operations should be case sensitive. ; $iOccurrence - an integer value. Which occurrence of the substring to find in the string. Use a ; negative occurrence to search from the right side. ; Return values .: Success - String ; Failure - Empty string as returned from StringLeft() ; Author ........: Sam Coates ; =============================================================================================================================== Func _StringLeft($sString, $sRemove, $iCaseSense = 0, $iOccurrence = 1) Return (StringLeft($sString, StringInStr($sString, $sRemove, $iCaseSense, $iOccurrence) - 1)) EndFunc ;==>_StringLeft ; #FUNCTION# ==================================================================================================================== ; Name ..........: _StringRandom ; Description ...: Returns a string of random characters ; Syntax ........: _StringRandom($iAmount[, $iType = 1]) ; Parameters ....: $iAmount - an integer value. Length of returned string ; $iType - [optional] an integer value. Default is 1. ; 1 - Return digits (0-9) ; 2 - Return hexadecimal (0-9, A - F) ; 3 - Return Alphanumeric upper (0-9, A - Z) ; 4 - Return Alphanumeric (0-9, A - Z, a - z) ; 5 - Return Alpha upper (A - Z) ; 6 - Return Alpha (A - Z, a - z) ; Return values .: Success - String ; Failure - Empty string and @error flag as follows: ; @error : 1 - $iAmount is not a positive integer ; 2 - $iType is out of bounds ; Author ........: Sam Coates ; =============================================================================================================================== Func _StringRandom($iAmount, $iType = 1) If $iAmount < 1 Or IsInt($iAmount) = 0 Then Return (SetError(-1, 0, "")) Local $sString = "" Local $iRandomLow = 1, $iRandomHigh = 62 #Tidy_Off Local Static $aCharId[63] = [0, Chr(48), Chr(49), Chr(50), Chr(51), Chr(52), Chr(53), Chr(54), Chr(55), Chr(56), Chr(57), Chr(65), Chr(66), Chr(67), _ Chr(68), Chr(69), Chr(70), Chr(71), Chr(72), Chr(73), Chr(74), Chr(75), Chr(76), Chr(77), Chr(78), Chr(79), Chr(80), _ Chr(81), Chr(82), Chr(83), Chr(84), Chr(85), Chr(86), Chr(87), Chr(88), Chr(89), Chr(90), Chr(97), Chr(98), Chr(99), _ Chr(100), Chr(101), Chr(102), Chr(103), Chr(104), Chr(105), Chr(106), Chr(107), Chr(108), Chr(109), Chr(110), Chr(111), _ Chr(112), Chr(113), Chr(114), Chr(115), Chr(116), Chr(117), Chr(118), Chr(119), Chr(120), Chr(121), Chr(122)] #Tidy_On If $iType = 1 Then ;; digits: 1 - 10 $iRandomHigh = 10 ElseIf $iType = 2 Then ;; hexadecimal: 1 - 16 $iRandomHigh = 16 ElseIf $iType = 3 Then ;; alnumupper: 1 - 36 $iRandomHigh = 36 ElseIf $iType = 4 Then ;; alnum: 1 - 62 $iRandomHigh = 62 ElseIf $iType = 5 Then ;; alphaupper: 11 - 36 $iRandomLow = 11 $iRandomHigh = 36 ElseIf $iType = 6 Then ;; alpha: 11 = 62 $iRandomLow = 11 $iRandomHigh = 62 Else Return (SetError(-2, 0, "")) EndIf For $i = 1 To $iAmount $sString &= $aCharId[Random($iRandomLow, $iRandomHigh, 1)] ;; append string with corresponding random character from ascii array Next Return ($sString) EndFunc ;==>_StringRandom ; #FUNCTION# ==================================================================================================================== ; Name ..........: _StringTrimLeft ; Description ...: Searches for a string inside a string, then removes everything on the left of that string ; Syntax ........: _StringTrimLeft($sString, $sRemove[, $iCaseSense = 0, $iOccurrence = 1]) ; Parameters ....: $sString - a string value. The string to search inside. ; $sRemove - a string value. The string to search for. ; $iCaseSense - an integer value. Flag to indicate if the operations should be case sensitive. ; $iOccurrence - an integer value. Which occurrence of the substring to find in the string. Use a ; negative occurrence to search from the right side. ; Return values .: Success - String ; Failure - Empty string as returned from StringTrimLeft() ; Author ........: Sam Coates ; =============================================================================================================================== Func _StringTrimLeft($sString, $sRemove, $iCaseSense = 0, $iOccurrence = 1) Return (StringTrimLeft($sString, StringInStr($sString, $sRemove, $iCaseSense, $iOccurrence) + StringLen($sRemove) - 1)) EndFunc ;==>_StringTrimLeft Examples:
      ConsoleWrite(_StringRandom(100, 6) & @CRLF) ConsoleWrite(_StringTrimLeft("C:\Windows\System32\cmd.exe", "C:\Windows\System32\") & @CRLF) ConsoleWrite(_StringLeft("C:\Windows\System32\cmd.exe", "cmd.exe") & @CRLF) ConsoleWrite(_FileToFileName("C:\Windows\System32\cmd.exe") & @CRLF) ConsoleWrite(_FileToFilePath("C:\Windows\System32\cmd.exe") & @CRLF) ConsoleWrite(_FileToFileExtension("C:\Windows\System32\cmd.exe") & @CRLF) ConsoleWrite(_StringRandom(6, 4) & "-" & _StringRandom(4, 4) & "-" & _StringRandom(4, 4) & "-" & _StringRandom(4, 4) & "-" & _StringRandom(6, 4)& @CRLF)  
    • By Sori
      Not going to dump the code down because it's essentially a keylogger.
      <snip>
    • By dinotom
      Can files be read from the web or the cloud?
      I am trying to read this file but get the file open error.
      #include <FileConstants.au3> #include <MsgBoxConstants.au3> ;Assign the file path to a variable Local $sFilePath = "C:\Automation\test.txt" Local $sFilePathAzure ="https://batlgroupimages.blob.core.windows.net/files/test.txt" Local $nLineNumberToLookFor = 0 ;Open the file test.txt in append mode. ;If the folder C:\Automation does not exist, it will be created. Local $hFileOpen = FileOpen($sFilePathAzure, $FO_APPEND + $FO_CREATEPATH) ;Display a message box in case of any errors. If $hFileOpen = -1 Then MsgBox($MB_SYSTEMMODAL, "", "An error occurred while opening the file.") EndIf ;Set the file position to beginning for reading the data from the beginning of the file. FileSetPos($hFileOpen, 0, $FILE_BEGIN) ;Read the data from the file using the handle returned by FileOpen ;Local $sFileRead = FileRead($hFileOpen) ;Read the 2nd line of data from the file using the handle returned by FileOpen Local $sFileReadLine = FileReadLine ($hFileOpen,2) ;Close the handle returned by FileOpen. FileClose($hFileOpen)  
    • By user4157124
      File- and stdout/-err (console) output of messages, regular- and COM Object errors, exit method and -code, etc.
      Just call _AUERLO_Log() after to be logged functions (no parameters required if preceding function returns @error on failure). Or replace ConsoleWrite() (and SciTE trace lines) by _AUERLO_Log() for existing scripts. _AUERLO_FileRead() and _AUERLO_View() to display error log file contents (or import as CSV file to Microsoft Excel for example). Register custom functions to adjust date/time format and replace or add output functionality (no UDF source code modifications required). Output to: file console (stdout and stderr) non-blocking notification (Beep(), SoundPlay(), etc.) prompt (GUI dialog; script-halting notification) Microsoft Windows Event Log custom (register function) Download:
      AUERLO v2.0.0 Remarks:
      AutoIt v3.3.14.3+ required. @ScriptLineNumber = 0 if from callback (like $AUERLO_OPT_FUNCEXIT, except for $AUERLO_OPT_FUNCCOM = Default), -1 if @compiled. Generates Au3Stripper warnings (to be ignored without consequence; #AutoIt3Wrapper_Au3stripper_OnError=ForceUse -safe). agpl-3.0 auerlo.au3 :
      _AUERLO_Set() _AUERLO_Log() _AUERLO_LogAlt() _AUERLO_LogWinAPI() _AUERLO_LogEnv() _AUERLO_Assert() _AUERLO_FileClear() _AUERLO_FileRead() _AUERLO_View() auerloConstants.au3 :
      $AUERLO_LVL__ENUM - debug levels, $AUERLO_OPT__ENUM - _AUERLO_Set() options, $AUERLO_RET__ENUM - Return codes, $AUERLO_ERR__ENUM - @error codes, and $AUERLO_ATR__ENUM - error item attributes. Usage explanation:
      If @error signifies failure (implicit logging) : _ArrayDisplay($sNotAnArray); Returns @error = 1. _AUERLO_Log() ; Logs as $AUERLO_LVL_TRACE, $AUERLO_LVL_ERROR on @error, $AUERLO_LVL_DEBUG on @extended. If @error Then ... ; _AUERLO_Log() transparently passes @error and @extended from _ArrayDisplay(). If return value signifies failure (explicit logging) : If FileExists('invalid path') = 0 Then _AUERLO_Log('', $AUERLO_LVL_ERROR) Global $g_hFile = FileOpen('invalid path') If $g_hFile = -1 Then _AUERLO_Log('', $AUERLO_LVL_ERROR) If (return) value or expression result signifies failure (implicit logging): Global $g_hFile = FileOpen('invalid path') _AUERLO_Assert(Not ($g_hFile = -1)) ; $AUERLO_LVL_DEBUG if True (success), $AUERLO_LVL_WARNING if False. _AUERLO_Assert(FileWrite($g_hFile, 'data')); Successfull return value (1) evaluates to True; failure (0) to False. _AUERLO_Assert(IsArray($g_sNotAnArray)) Import error log file contents: Global $g_aArray2D = _AUERLO_FileRead(); Reads from current error log file. _AUERLO_View($g_aArray2D) Configuration ($AUERLO_OPT__ENUM in auerloConstants.au3 for description of all options) : _AUERLO_Set($AUERLO_OPT_LOGFILE, False) ; Disables output to error log file. _AUERLO_Set($AUERLO_OPT_LOGSTD, True) ; Enables output to stdout/stderr (console). _AUERLO_Set($AUERLO_OPT_FNCEXIT, Default) ; Registers default exit handler (no script exit logging without). _AUERLO_Set($AUERLO_OPT_FNCEXIT, Null) ; Deregisters default exit handler. _AUERLO_Set($AUERLO_OPT_FNCCOM, Default) ; Registers default COM Object error handler (no COM error logging without). _AUERLO_Set($AUERLO_OPT_FNCCOM, Null) ; Deregisters COM Object error handler. _AUERLO_Set($AUERLO_OPT_FNCCOM, YourFunc); Registers custom COM Object error handler YourFunc().  
×
×
  • Create New...