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
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 emendelson
      Using some very ingenious scripts that I found on this forum, I've put together a special-purpose folder watcher that watches a specified folder for printer output files and then either send them to a printer or converts them to a PDF and prints or opens the PDF. The page about this utility is here:
      http://www.columbia.edu/~em36/printfileprinter.html
      The one serious problem that it has is that it seems not to detect a new file if there are more than two or three files already in the watched folder. I can't figure out what I'm doing wrong, and will be grateful for any help. Here is the relevant part of the script. I've left out the functions that test whether the file is in use or not, and that send the raw data to the printer or create a PDF, etc. I hope there's enough code here to make sense of it, and will be very grateful for any help. Again, the problem is that the script doesn't detect newly-created files in watched folders with more than a very few files already in it.
      My totally ignorant guess is that the problem is in the line $iID = _WinAPI_WaitForMultipleObjects(2, $paObj, 0, 0) - but I don't know how to change it and of course I'm only guessing whether it's relevant or not. Many thanks
       
      Global $g_ahObj[2] $g_ahObj[0] = _WinAPI_FindFirstChangeNotification($watchPath, $FILE_NOTIFY_CHANGE_FILE_NAME) $g_ahObj[1] = _WinAPI_FindFirstChangeNotification($watchPath, $FILE_NOTIFY_CHANGE_DIR_NAME) If (Not $g_ahObj[0]) Or (Not $g_ahObj[1]) Then MsgBox(BitOR($MB_ICONERROR, $MB_SYSTEMMODAL), 'Error', 'Unable to create change notification.') Exit EndIf Local $tObjs = DllStructCreate('ptr;ptr') Local $paObj = DllStructGetPtr($tObjs) For $i = 0 To 1 DllStructSetData($tObjs, $i + 1, $g_ahObj[$i]) Next Local $iID While 1 Sleep(100) $select = 0 $print = 0 $format = "" Local $tempPDF $tempPDF = 0 $iID = _WinAPI_WaitForMultipleObjects(2, $paObj, 0, 0) Switch $iID Case 0 ; WAIT_OBJECT_0 ; ConsoleWrite('A file was created, renamed, or deleted in the directory.' & @CRLF) Local $hSearch = FileFindFirstFile($watchPath & "\*") Local $sFileName = "", $iResult = 0 Local $sFilePath = "" While 1 $sFileName = FileFindNextFile($hSearch) ; If there is no more file matching the search. If @error Then ExitLoop $sFilePath = $watchPath & "\" & $sFileName Local $fileUsed $fileUsed = 0 $fileUsed = _FileIsUsed($sFilePath) If $fileUsed = 1 Then While 1 Sleep(100) $fileUsed = _FileIsUsed($sFilePath) If $fileUsed = 0 Then ExitLoop WEnd EndIf If StringInStr($sFileName, "raw") Then If StringInStr($sFileName, "select") Then $select = 1 PrintRawFile($sFilePath, $select) Else If StringInStr($sFileName, "lg.") Then $pageSize = "legal" ElseIf StringInStr($sFileName, "a4.") Then $pageSize = "a4" ElseIf StringInStr($sFileName, "us.") Then $pageSize = "letter" EndIf $pdfTemp = 0 If StringLower(StringLeft($sFileName, 7) = "pdftemp") Then $pdfTemp = 1 If StringInStr($sFileName, ".pcl") Then $format = "pcl" $print = 1 If StringLeft($sFileName, 6) = "select" Then $select = 1 $print = 1 ElseIf StringLeft($sFileName, 3) = "pdf" Then $select = 0 $print = 0 EndIf MakePDF($sFilePath, $format, $print, $select, $pageSize, $pdfTemp) ElseIf StringInStr($sFileName, ".ps") Then $format = "ps" $print = 1 If StringLeft($sFileName, 6) = "select" Then $select = 1 $print = 1 ElseIf StringLeft($sFileName, 3) = "pdf" Then $select = 0 $print = 0 EndIf MakePDF($sFilePath, $format, $print, $select, $pageSize, $pdfTemp) ElseIf StringInStr($sFileName, ".esc") Then Sleep(200) $format = "epson" $print = 1 If StringLeft($sFileName, 6) = "select" Then $select = 1 $print = 1 ElseIf StringLeft($sFileName, 3) = "pdf" Then $select = 0 $print = 0 EndIf MakePDF($sFilePath, $format, $print, $select, $pageSize, $pdfTemp) ElseIf StringInStr($sFileName, ".prn") Then $format = GetFileFormat($sFilePath) $print = 1 If StringLeft($sFileName, 6) = "select" Then $select = 1 $print = 1 ElseIf StringLeft($sFileName, 3) = "pdf" Then $select = 0 $print = 0 EndIf ConsoleWrite("PRN test format: " & $format & @CRLF) MakePDF($sFilePath, $format, $print, $select, $pageSize, $pdfTemp) EndIf EndIf ; Display the file name. ; $iResult = MsgBox(BitOR($MB_SYSTEMMODAL, $MB_OKCANCEL), "", $watchPath & "\" & $sFileName) ;~ RunWait(@ComSpec & " /c notepad.exe " & $watchPath & "\" & $sFileName) ;~ FileDelete($watchPath & "\" & $sFileName) If $iResult <> $IDOK Then ExitLoop ; If the user clicks on the cancel/close button. WEnd ; Close the search handle. FileClose($hSearch) Case 1 ; WAIT_OBJECT_0 + 1 ; ConsoleWrite('A directory was created, renamed, or deleted.' & @CRLF) Case Else ContinueLoop EndSwitch If Not _WinAPI_FindNextChangeNotification($g_ahObj[$iID]) Then MsgBox(BitOR($MB_ICONERROR, $MB_SYSTEMMODAL), 'Error', 'Unexpected error.') Exit EndIf WEnd  
    • By xYuri
      This simple dllcall gives me error 5, access denied,
      Func _WinAPI_VkKeyScan($__key) _WinAPI_SetLastError(0) $res = DllCall('User32.dll', 'SHORT', 'VkKeyScan', 'CHAR', $__key) _xConsole('res: '&$res) $_LastErr = _WinAPI_GetLastError() If $_LastErr <> 0 Then _xConsole('Err: {' & $_LastErr & '}> ' & _WinAPI_GetLastErrorMessage()) Return $res EndFunc Am i doing something wrong?
      Also tried VkKeyScanA and W
      Edit:
      I want to send `:` via PostMessage() WM_KEYDOWN
    • 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>
×
×
  • Create New...