Sign in to follow this  
Followers 0
DXRW4E

_FileListToArrayEx

40 posts in this topic

#1 ·  Posted (edited)

Hi All, Sorry for my English

#include-once

; #UDF# =======================================================================================================================
; Title .........: File List To Array
; AutoIt Version : 3.3.8.1
; Language ......: English
; Description ...: Lists files and\or folders in a specified path (Similar to using Dir with the /B Switch)
; Author(s) .....: DXRW4E
; Notes .........:
; ===============================================================================================================================

; #CURRENT# =====================================================================================================================
;~ _FileListToArrayEx
; ===============================================================================================================================

; #FUNCTION# =======================================================================================================================================================
; Name...........: _FileListToArrayEx
; Description ...: Lists files and\or folders in a specified path (Similar to using Dir with the /B Switch)
; Syntax.........: _FileListToArrayEx($sPath[, $sFilter = "*"[, $iFlag = 0]])
; Parameters ....: $sPath   - Path to generate filelist for.
;                 $sFilter - Optional the filter to use, default is *. (Multiple filter groups such as "All "*.png|*.jpg|*.bmp") Search the Autoit3 helpfile for the word "WildCards" For details.
;                 $iFlag   - Optional: specifies whether to return files folders or both Or Full Path (add the flags together for multiple operations):
;                 |$iFlag = 0 (Default) Return both files and folders
;                 |$iFlag = 1 Return files only
;                 |$iFlag = 2 Return Folders only
;                 |$iFlag = 4 Search SubDirectory
;                 |$iFlag = 8 Return Full Path
;                 |$iFlag = 16 $sFilter do Case-Sensitive matching (By Default $sFilter do Case-Insensitive matching)
;                 |$iFlag = 32 Disable the return the count in the first element - effectively makes the array 0-based (must use UBound() to get the size in this case).
;                   By Default the first element ($array[0]) contains the number of file found, the remaining elements ($array[1], $array[2], etc.)
;                 |$iFlag = 64 $sFilter is REGEXP Mod, See Pattern Parameters in StringRegExp (Can not be combined with flag 16)
;                 |$iFlag = 128 Return Backslash at the beginning of the file name, example Return "\Filename1.xxx" (Can not be combined with flag 8)
; Return values .: Failure - @Error
;                 |1 = Path not found or invalid
;                 |2 = Invalid $sFilter
;                 |3 = No File(s) Found
; Author ........: DXRW4E
; Modified.......:
; Remarks .......: The array returned is one-dimensional and is made up as follows:
;                               $array[0] = Number of Files\Folders returned
;                               $array[1] = 1st File\Folder
;                               $array[2] = 2nd File\Folder
;                               $array[3] = 3rd File\Folder
;                               $array[n] = nth File\Folder
; Related .......:
; Link ..........:
; Example .......: Yes
; Note ..........: Special Thanks to SolidSnake & Tlem
; ==================================================================================================================================================================
Func _FileListToArrayEx($sPath, $sFilter = "*", $iFlag = 0)
    $sPath = StringRegExpReplace($sPath & "\", "(?!\A)[\\/]+\h*", "\\")
    If Not FileExists($sPath) Then Return SetError(1, 1, "")
    If StringRegExp($sFilter, StringReplace('^\s*$|\v|[\\/:><"]|^\||\|\||\|$', "[" & Chr(BitAND($iFlag, 64) + 28) & '\/:><"]|^\||\|\||\|$', "\\\\")) Then Return SetError(2, 2, "")
    Local $hSearch, $sFile, $sFileList, $sSubDir = BitAND($iFlag, 4), $sDelim = "|", $sDirFilter = StringReplace($sFilter, "*", "")
    $hSearch = FileFindFirstFile($sPath & "*")
    If @Error Then Return SetError(3, 3, "")
    Local $hWSearch = $hSearch, $hWSTMP, $SearchWD, $Extended, $iFlags = StringReplace(BitAND($iFlag, 1) + BitAND($iFlag, 2), "3", "0")
    If BitAND($iFlag, 8) Then $sDelim &= $sPath
    If BitAND($iFlag, 128) Then $sDelim = "|\"
    If Not BitAND($iFlag, 64) Then $sFilter = StringRegExpReplace(BitAND($iFlag, 16) & "(?i)(", "16\(\?\i\)|\d+", "") & StringRegExpReplace(StringRegExpReplace(StringRegExpReplace(StringRegExpReplace($sFilter, "[^*?|]+", "\\Q$0\\E"), "\\E(?=\||$)", "$0\$"), "(?<=^|\|)\\Q", "^$0"), "\*+", ".*") & ")"
    While 1
        $sFile = FileFindNextFile($hWSearch)
        If @Error Then
            If $hWSearch = $hSearch Then ExitLoop
            FileClose($hWSearch)
            $hWSearch -= 1
            $SearchWD = StringLeft($SearchWD, StringInStr($SearchWD, "\", 1, -2))
        ElseIf $sSubDir Then
            $Extended = @Extended
            If ($iFlags + $Extended <> 2) Then
                If $sDirFilter Then
                    If StringRegExp($sFile, $sFilter) Then $sFileList &= $sDelim & $SearchWD & $sFile
                Else
                    $sFileList &= $sDelim & $SearchWD & $sFile
                EndIf
            EndIf
            If Not $Extended Then ContinueLoop
            $hWSTMP = FileFindFirstFile($sPath & $SearchWD & $sFile & "\*")
            If $hWSTMP = -1 Then ContinueLoop
            $hWSearch = $hWSTMP
            $SearchWD &= $sFile & "\"
        Else
            If ($iFlags + @Extended = 2) Or StringRegExp($sFile, $sFilter) = 0 Then ContinueLoop
            $sFileList &= $sDelim & $sFile
        EndIf
    WEnd
    FileClose($hSearch)
    If Not $sFileList Then Return SetError(3, 3, "")
    Return StringSplit(StringTrimLeft($sFileList, 1), "|", StringReplace(BitAND($iFlag, 32), "32", 2))
EndFunc    ;==>_FileListToArrayEx

Registry Key List To Array - Read Registry KeySybKey

_FileListToArrayEx.au3

Edited by DXRW4E
1 person likes this

apps-odrive.pngdrive_app_badge.png box-logo.png new_logo.png MEGA_Logo.png

Share this post


Link to post
Share on other sites



Wow, very nice! Thanks for sharing!

Ian


My projects:

  • IP Scanner - Multi-threaded ping tool to scan your available networks for used and available IP addresses, shows ping times, resolves IPs in to host names, and allows individual IPs to be pinged.
  • INFSniff - Great technicians tool - a tool which scans DriverPacks archives for INF files and parses out the HWIDs to a database file, and rapidly scans the local machine's HWIDs, searches the database for matches, and installs them.
  • PPK3 (Persistent Process Killer V3) - Another for the techs - suppress running processes that you need to keep away, helpful when fighting spyware/viruses.
  • Sync Tool - Folder sync tool with lots of real time information and several checking methods.
  • USMT Front End - Front End for Microsoft's User State Migration Tool, including all files needed for USMT 3.01 and 4.01, 32 bit and 64 bit versions.
  • Audit Tool - Computer audit tool to gather vital hardware, Windows, and Office information for IT managers and field techs. Capabilities include creating a customized site agent.
  • CSV Viewer - Displays CSV files with automatic column sizing and font selection. Lines can also be copied to the clipboard for data extraction.
  • MyDirStat - Lists number and size of files on a drive or specified path, allows for deletion within the app.
  • 2048 Game - My version of 2048, fun tile game.
  • Juice Lab - Ecigarette liquid making calculator.
  • Data Protector - Secure notes to save sensitive information.
  • VHD Footer - Add a footer to a forensic hard drive image to allow it to be mounted or used as a virtual machine hard drive.
  • Find in File - Searches files containing a specified phrase.

Share this post


Link to post
Share on other sites

Nice share! Thanks :)

Share this post


Link to post
Share on other sites
Nice ! Thanks !

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

@All

Thanks

Updated

Added Multiple filter groups, look at the first post

Ciao.

Edited by DXRW4E

apps-odrive.pngdrive_app_badge.png box-logo.png new_logo.png MEGA_Logo.png

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Perhaps a Developers, Moderator, MVP or other, perhaps need to review this (see if need anything else to repair improve something or other), and perhaps use this to defualt (and the same code, the one defined by default, only it was updated), as it seems that the code more clean (39 line) and I think works faster, so maybe it also closes the history of _FileListToArray + Search subdirectory

sorry for my English

Ciao a tutti.

Edited by DXRW4E

apps-odrive.pngdrive_app_badge.png box-logo.png new_logo.png MEGA_Logo.png

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

@JohnOne

The SmOke_N FileListToArrayEx function presents two problems with regard to that of the DXRW4E :

1st : She's more slowly (we talk about some ms, so it's not really important)

2nd : The return are not true, because if I search for this _FileListToArrayEx2(@WindowsDir, "*.dll", 1), it return me files like this C:WINDOWSInstaller$PatchCache$Managed5C1093C35543A0E32A41B090A305076A4.0.30319system.net.dll_x86

Edited by Tlem

Best Regards.Thierry

Share this post


Link to post
Share on other sites

@JohnOne

The SmOke_N FileListToArrayEx function presents two problems with regard to that of the DXRW4E :

1st : She's more slowly (we talk about some ms, so it's not really important)

2nd : The return are not true, because if I search for this _FileListToArrayEx2(@WindowsDir, "*.dll", 1), it return me files like this C:WINDOWSInstaller$PatchCache$Managed5C1093C35543A0E32A41B090A305076A4.0.30319system.net.dll_x86

Hmm, that's an expected return. That is a mask search, not an extension search.


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

as it seems that the code more clean (39 line) and I think works faster, so maybe it also closes the history of _FileListToArray + Search subdirectory

Not trying to pick on you.. but you cant call it 39 lines, or call it clean when you have a line like this in your code:

Local $hWSearch = $hSearch, $hWSTMP = $hSearch, $SearchWD, $FPath = StringRegExpReplace(StringRegExpReplace($sSDir, '[^2]+', ""), "2+", StringRegExpReplace($sPath, '\\', "\\\\")), $sSDirF[3] = [0, StringReplace($sSDirFTMP, "*", ""), "(?i)(" & StringRegExpReplace(StringRegExpReplace(StringRegExpReplace(StringRegExpReplace(StringRegExpReplace(StringRegExpReplace("|" & $sSDirFTMP & "|", '\|\h*\|[\|\h]*', "\|"), '[\^\$\(\)\+\[\]\{\}\,\.\=]', "\\$0"), "\|([^\*])", "\|^$1"), "([^\*])\|", "$1\$\|"), '\*', ".*"), '^\||\|$', "") & ")"]

Share this post


Link to post
Share on other sites

Hi Beege, that's not a problem is called only once, and it is a necessary thing, the_FileListToArrayEx uses only 1 While, more clean so I do not think that there is

and sorry for my English

Ciao.


apps-odrive.pngdrive_app_badge.png box-logo.png new_logo.png MEGA_Logo.png

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Hmm, that's an expected return. That is a mask search, not an extension search.

Sorry, but I can't be agree with you. Make a try with the Windows search. If you search for this mask *.dll the result never return files like system.net.dll_x86.

If I want to search for these files, I use this mask : *.dll*

So for me, it can't be an expected return.

Edited by Tlem

Best Regards.Thierry

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

There's a problem in this function. Your $sDir parameter has incorrect information in the header, it states:

; $sSDir - Optional: specifies whether to return files folders or both

; |$sSDir=1 Search subdirectory

; |$sSDir=2 Search subdirectory & Return Full Path

But inside the function itself, it doesn't look at whether $sSDir is 1 or 2, it returns the same results regardless of what you set $sSDir to, unless you set it to 0.

ElseIf $sSDir Then

That line only checks if it's True (not 0) or False (0). This follows the default parameter of the function where you set $sSDir=0.

I did some further testing and found out I was incorrect in my original assumption. The problem actually isn't that 1 and 2 for the $sSDir parameter return the same results, because they don't they return different results I just had made an error in my test script. The problem is that the $sSDir parameter takes a third option that's not mentioned, which is 0, which tells the script to not do a recursive search in the target folder. My apologies for that, but the header information is still missing that point, but definitely not a bug in this UDF.

EDIT:Corrected wrong information in my original post.

Edited by BrewManNH

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 Gude
How 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

Share this post


Link to post
Share on other sites

Hi,

I can't figure out a way to obtain non-recursive & fullpath result, instead of the non-recursive & filename only result (obtained through built-in parameter $sSDir=0).

Could someone help me please ?

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

If you search files (or subdirectory) in a specific directory without the recursive option, why did you need to store the path ???

You know it, so it's easy to add it on your result :

#include "_FileListToArrayEx.au3"
$Path = "C:"
$aArray = _FileListToArrayEx($Path, "*", 1, 0)
For $i = 1 To UBound($aArray) - 1
ConsoleWrite($Path & $aArray[$i] & @CRLF)
Next

EDIT : But I agree with you, DXRW4E would have been able to separate the recursive option and the return of full path. ;)

Edited by Tlem

Best Regards.Thierry

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

I did not want to change the original code, that and the setting and the original code for this reason the left so

However who wants to will be able to modify the code if they suffered, just put it so

$FPath = StringRegExpReplace(StringRegExpReplace($sSDir, '[^2]+', ""), "2+", StringRegExpReplace($sPath, '\\', "\\\\"))

in

$FPath = $sPath

So Default and always full path (no need to use more $sSDir = 2)

Sorry for my english

Edited by DXRW4E

apps-odrive.pngdrive_app_badge.png box-logo.png new_logo.png MEGA_Logo.png

Share this post


Link to post
Share on other sites

Thank you both for your feed-back

@TIem: I'm looking for files in a list of directories (specified in an XML file) ; each of these directories has a recursivity search boolean param. I thought about your solution, but it seemed to me more convenient and elegant to change the _FileListToArrayEx behaviour itself.

At the end of the day, I'm able to implement your proposal, because it's so easy.

@DRXW4E: I'm afraid I do not understand where to implement this or these new lines of code (not because of your english!). So, I'm going to adopt TIen proposal, except if you were so kind to indicate more clearly where to put this code excatly in the function, or even, separate recursitvity param from full path param, as stated by TIem.

Bye,

Share this post


Link to post
Share on other sites

First post of topics and code of _FileListToArrayEx.au3, Replace the line shown in post above, after _FileListToArrayEx.au3 always return full path

Ciao.


apps-odrive.pngdrive_app_badge.png box-logo.png new_logo.png MEGA_Logo.png

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

@DXRW4E

Your proposition doesn't work for root directory. You must modifie this part too

$sFileList &= $sDelim & $sFile
by
$sFileList &= $sDelim & $FPath & $sFile

I understand why you doesn't want make more modification on your function, but in my opinion, the recursive search and full path return must be a separate option.

To take care about what BrewManNH said about the $sSDir flag 0 and what FVn ask, this is my adaptation of your function :

#include-once
;#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
; #FUNCTION# ====================================================================================================================
; Name...........: _FileListToArrayEx
; Description ...: Lists files andor folders in a specified path (Similar to using Dir with the /B Switch)
; Syntax.........: _FileListToArrayEx($sPath[, $sFilter = "*"[, $iFlag = 0 [, $iSDir = 0 [, $iFPath = 1]]]])
; Parameters ....: $sPath   - Path to generate filelist for.
;                 $sFilter - Optional the filter to use, default is *. (Multiple filter groups such as "*.png|*.jpg|*.bmp") Search the Autoit3 helpfile for the word "WildCards" For details.
;                 $iFlag   - Optional: specifies whether to return files folders or both
;                   |$iFlag=0 (Default) Return both files and folders
;                   |$iFlag=1 Return files only
;                   |$iFlag=2 Return Folders only
;                 $iSDir   - Optional: specifies whether to return files folders or both
;                   |$iSDir=0 Do not Search subdirectory (default)
;                   |$iSDir=1 Search subdirectory
;                 $iFPath  - Optional: specifies whether to return files folders or both
;                   |$iFPath=0 Do not return full path
;                   |$iFPath=1 Return full path (Default)
; Return values .: @Error
;     |1 = Path not found or invalid
;                   |2 = Invalid $sFilter
;                   |3 = Invalid $iFlag
;                   |4 = No File(s) Found
; Author ........: SolidSnake <metalgx91 at="" gmail="" dot="" com="">
; Modified.......:
; Remarks .......: The array returned is one-dimensional and is made up as follows:
;                               $array[0] = Number of FilesFolders returned
;                               $array[1] = 1st FileFolder
;                               $array[2] = 2nd FileFolder
;                               $array[3] = 3rd FileFolder
;                               $array[n] = nth FileFolder
; Related .......:
; Link ..........: http://www.autoitscript.com/forum/topic/131277-filelisttoarrayex
; Example .......: Yes
; Note ..........: Special Thanks to Helge and Layer for help with the $iFlag update speed optimization by code65536, pdaughe
;                 Update By DXRW4E
;                 Update By Tlem
; ===============================================================================================================================
Func _FileListToArrayEx($sPath, $sFilter = "*", $iFlag = 0, $iSDir = 0, $iFPath = 1)
Local $hSearch, $sFile, $sFileList, $sDelim = "|", $sSDirFTMP = $sFilter, $FPath
$sPath = StringRegExpReplace($sPath, "[/]+z", "") & "" ; ensure single trailing backslash
If Not FileExists($sPath) Then Return SetError(1, 1, "")
If StringRegExp($sFilter, "[/:><]|(?s)As*z") Then Return SetError(2, 2, "")
If Not ($iFlag = 0 Or $iFlag = 1 Or $iFlag = 2) Then Return SetError(3, 3, "")
$hSearch = FileFindFirstFile($sPath & "*")
If @error Then Return SetError(4, 4, "")
If $iFPath = 1 Then $FPath = $sPath
Local $hWSearch = $hSearch, $hWSTMP = $hSearch, $SearchWD, $sSDirF[3] = [0, StringReplace($sSDirFTMP, "*", ""), "(?i)(" & StringRegExpReplace(StringRegExpReplace(StringRegExpReplace(StringRegExpReplace(StringRegExpReplace(StringRegExpReplace("|" & $sSDirFTMP & "|", '|h*|[|h]*', "|"), '[^$()+[]{},.=]', "$0"), "|([^*])", "|^$1"), "([^*])|", "$1$|"), '*', ".*"), '^|||$', "") & ")"]
While 1
  $sFile = FileFindNextFile($hWSearch)
  If @error Then
   If $hWSearch = $hSearch Then ExitLoop
   FileClose($hWSearch)
   $hWSearch -= 1
   $SearchWD = StringLeft($SearchWD, StringInStr(StringTrimRight($SearchWD, 1), "", 1, -1))
  ElseIf $iSDir Then
   $sSDirF[0] = @extended
   If ($iFlag + $sSDirF[0] <> 2) Then
    If $sSDirF[1] Then
     If StringRegExp($sFile, $sSDirF[2]) Then $sFileList &= $sDelim & $FPath & $SearchWD & $sFile
    Else
     $sFileList &= $sDelim & $FPath & $SearchWD & $sFile
    EndIf
   EndIf
   If Not $sSDirF[0] Then ContinueLoop
   $hWSTMP = FileFindFirstFile($sPath & $SearchWD & $sFile & "*")
   If $hWSTMP = -1 Then ContinueLoop
   $hWSearch = $hWSTMP
   $SearchWD &= $sFile & ""
  Else
   If ($iFlag + @extended = 2) Or StringRegExp($sFile, $sSDirF[2]) = 0 Then ContinueLoop
   $sFileList &= $sDelim & $FPath & $sFile
  EndIf
WEnd
FileClose($hSearch)
If Not $sFileList Then Return SetError(4, 4, "")
Return StringSplit(StringTrimLeft($sFileList, 1), "|")
EndFunc   ;==>_FileListToArrayEx
Edited by Tlem

Best Regards.Thierry

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

@Tlem

Hi Tlem, Thank You, you're right, or forget that the full path is used only for subdir

to be honest I do not like much the fate of using many flags in a function (I mean best to use as little as possible, BITAND and really nice), I think the better way and what he or posted in first post

However who like that way will be able to use your script (that is already OK) in post above (_FileListToArrayEx($sPath, $sFilter = "*", $iFlag = 0, $iSDir = 0, $iFPath = 1)), so I think everything is OK

Many Thanks Again

@FVN

Now you can use for example

$iFlag = 0 + 8 --> Return both files and folders and Full Path

Or

$iFlag = 0 + 8 + 4 --> Return both files and folders and subdirectory and Full Path

Or

$iFlag = 1 + 8 + 4 --> Return files only and subdirectory and Full Path

Or

$iFlag = 1 + 8 --> Return files only and Full Path

ect ect ect ect

@All

already updated the first post

sorry again for my English

Ciao.

Edited by DXRW4E

apps-odrive.pngdrive_app_badge.png box-logo.png new_logo.png MEGA_Logo.png

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
Sign in to follow this  
Followers 0

  • Similar Content

    • Dimmae
      By Dimmae
      Hello,
      at first: i'm new here, so please forgive me my mistakes, and show them to me, just that i can learn to do better in the future.
      Now to my Problem: i have an excel sheet, where i just need some columns for further actions, but i have no idea how to add single columns to a new array.
      I found the following code(the one i just added as a file) from 'water' in this forum, but i wont get how i could add multiple columns into a new array.
      The biggest problem in my situation is that i dont know the count of the rows i need for the array, i just got a fix number of rows, which is 4.
       
      Hope you can help me, and sry again for this 'unlucky illustration'.
       
      btw: how can i add code shown as code here, instead of posting it as a attached file?.
       
       
       
      autoit-select-column.au3
      defects.xlsx
    • imitto
      By imitto
      Hello all!
      I use Autoit for a while, already made some automation for a TV station's master control room with it. I made a UDF to easily work with PAL timecode and time with milliseconds, convert, add or subtract them. Feel free to use it if you want something like this
      #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Res_Description=PAL Timecode Calculator UDF #AutoIt3Wrapper_Res_LegalCopyright=horvath.imre@gmail.com #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ; ; #FUNCTION# ; Name...........: _tcAdd ; Description....: Returns addition of two timecodes ; Syntax.........: _tcAdd($fTc1, fTc2 [, $fFormat = "P"]) ; ; Parameters.....: $fTc1 - First timecode in hh:mm:ss.ff format ; $fTc2 - Second timecode in hh:mm:ss.ff format ; $fFormat - Time base - "P" (default): PAL (25 fps) ; "M" : millisecond ; ; Return value...: Sum of the two timecode in the selected format Func _tcAdd($fTc1, $fTc2, $fFormat = "P", $fHourFormat = 1) Local $fMs1 = _tcToMs($fTc1) Local $fMs2 = _tcToMs($fTc2) Local $fSumMs = $fMs1 + $fMs2 Return _msToTc($fSumMs, $fFormat, $fHourFormat) EndFunc ; #FUNCTION# ; Name...........: _tcsSub ; Description....: Returns addition of two timecodes ; Syntax.........: _tcSub($fTc1, fTc2 [, $fFormat = "P"]) ; ; Parameters.....: $fTc1 - First timecode in hh:mm:ss.ff format ; $fTc2 - Second timecode in hh:mm:ss.ff format ; $fFormat - Time base - "P" (default): PAL (25 fps) ; "M" : millisecond ; ; Return value...: Subtract $fTc2 from $fTc1 in the source format Func _tcSub($fTc1, $fTc2, $fFormat = "P") Local $fMs1 = _tcToMs($fTc1) Local $fMs2 = _tcToMs($fTc2) Local $fSumMs = $fMs1 - $fMs2 If $fSumMs < 0 Then $fSumMs = _tcToMs("24:00:00.00") - ($fSumMs * -1) EndIf Return _msToTc($fSumMs, $fFormat) EndFunc ; #FUNCTION# ; Name...........: _tcToMs ; Description....: Returns timecode converted to total milliseconds ; Syntax.........: _tcToMs($fTc) ; ; Parameters.....: $fTc - Timecode in hh:mm:ss.ff or hh:mm:ss:xxx format, where xxx are milliseconds ; ; Return value...: Milliseconds as an integer value Func _tcToMs($fTc) Local $fTemp = StringSplit($fTc, ":.") Local $fChr = StringLen($fTemp[4]) Switch $fChr Case 2 Return ($fTemp[4] * 40) + ($fTemp[3] * 1000) + ($fTemp[2] * 60000) + ($fTemp[1] * 3600000) Case 3 Return ($fTemp[4]) + ($fTemp[3] * 1000) + ($fTemp[2] * 60000) + ($fTemp[1] * 3600000) EndSwitch EndFunc ; #FUNCTION# ; Name...........: _msToTc ; Description....: Converts total milliseconds to timecode ; Syntax.........: _msToTc($fIn, $fFormat = "P", $fHourFormat = 1) ; ; Parameters.....: $fIn - Time in milliseconds ; $fFormat - Output format "P": PAL TC (default) ; "M": hh:mm:ss.xxx where xxx are milliseconds ; $fHourFormat - Hour format "1": max. value is 23, then starts from 0 (default) ; "0": hours can be more then 23 ; ; Return value...: Timecode as string in the selected format Func _msToTc($fIn, $fFormat = "P", $fHourFormat = 1) Switch $fFormat Case "P" Local $fFr = StringFormat("%02i", (StringRight($fIn, 3) - Mod(StringRight($fIn, 3), 40)) / 40) Case "M" Local $fFr = StringFormat("%03i", StringRight($fIn, 3)) EndSwitch $fIn = StringTrimRight($fIn, 3) Local $fSec = StringFormat("%02i", Mod($fIn, 60)) $fIn -= $fSec Local $fMinTot = $fIn / 60 Local $fMin = StringFormat("%02i", Mod($fMinTot, 60)) $fIn -= $fMin*60 Local $fHourTot = $fIn / 60 / 60 Switch $fHourFormat Case 1 $fHour = StringFormat("%02i", Mod($fHourTot, 24)) Case 0 $fHour = StringFormat("%02i", $fHourTot) EndSwitch Return($fHour & ":" & $fMin & ":" & $fSec & "." & $fFr) EndFunc ; #FUNCTION# ; Name...........: _tcFormatChange ; Description....: Toggle TC format ; Syntax.........: _tcFormatChange($fTc) ; ; Parameters.....: $fTc - Timecode in hh:mm:ss.ff or hh:mm:ss:xxx format, where xxx are milliseconds ; ; Return value...: PAL timecode or time with milliseconds as string, depends on input Func _tcFormatChange($fTc) Local $fTemp = StringSplit($fTc, ":.") Local $fChr = StringLen($fTemp[4]) Switch $fChr Case 2 Return $fTemp[1]&":"&$fTemp[2]&":"&$fTemp[3]&"."&StringFormat("%03i", $fTemp[4]*40) Case 3 Return $fTemp[1]&":"&$fTemp[2]&":"&$fTemp[3]&"."&StringFormat("%02i", ($fTemp[4]-Mod($fTemp[4], 40))/40) EndSwitch EndFunc And the example script:
      #include<_PAL_TC_Calc.au3> $palTC1 = "00:01:12.20" $palTC2 = "23:59:50.02" $msTC1 = "00:01:12.800" $msTC2 = "23:59:50.120" MsgBox(0, "1", _tcAdd($palTC1, $palTC2)); Adds $palTC1 to $palTC2, turns hour back to 0 after 23, returns PAL TC format MsgBox(0, "2", _tcAdd($palTC1, $palTC2, "M")); Adds $palTC1 to $palTC2, turns hour back to 0 after 23, returns time with milliseconds format MsgBox(0, "3", _tcAdd($palTC1, $palTC2, "M", 0)); Adds $palTC1 to $palTC2, hours can be infinite, returns time with milliseconds format MsgBox(0, "4", _tcAdd($msTC1, $msTC2)); Adds $palTC1 to $palTC2, turns hour back to 0 after 23, returns PAL TC format MsgBox(0, "5", _tcAdd($msTC1, $msTC2, "M")); Adds $palTC1 to $palTC2, turns hour back to 0 after 23, returns time with milliseconds format MsgBox(0, "6", _tcAdd($msTC1, $msTC2, "M", 0)); Adds $palTC1 to $palTC2, hours can be infinite, returns time with milliseconds format MsgBox(0, "7", _tcSub($palTC2, $palTC1)); Subtract $palTC1 from $palTC2, returns PAL TC format MsgBox(0, "8", _tcSub($palTC2, $palTC1, "M")); Subtract $palTC1 from $palTC2, time with milliseconds format MsgBox(0, "9", _tcSub($msTC1, $msTC2)); Subtract $palTC1 from $palTC2, returns PAL TC format - when hits zero, counts back from 24:00:00.00 MsgBox(0, "10", _tcSub($msTC1, $msTC2, "M")); Subtract $palTC1 from $palTC2, time with milliseconds format - when hits zero, counts back from 24:00:00.000 MsgBox(0, "11", _tcFormatChange($palTC2)); Convert PAL TC to time with milliseconds and back MsgBox(0, "12", _tcFormatChange($msTC2)); Convert PAL TC to time with milliseconds and back  
      TC_CALC_example.au3
      _PAL_TC_Calc.au3
    • TRAGENALPHA
      By TRAGENALPHA
      A small UDF to Modify the Console Interface.
      #include-once ;#AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7 ; =============================================================================================================================== ; Name...........: Console Modify ; Description ...: A small UDF to manipulate the Console Interface for scripts that are compiled as a console application. ; Syntax.........: _ConsoleClear() -- Clears the Console ; _ConsoleTitle("VALUE") - Sets the console title. ; _ConsoleWindow([WIDTH BUFFER SIZE], [HEIGHT BUFFER SIZE]) - Sets the Width and Height Buffer size of the console. ; Parameters ....: $bh6e5v_ctval = Title of the Console Window. ; $bh6e5v_cwwidth = Window width buffer size. ; $bh6e5v_cwheight = Window height buffer size. ; Return values .: True = Console window buffer size has been changed ; False = Failed to change console window buffer size. ; Author ........: TRAGENALPHA <3 ; Example .......: _ConsoleTitle("This is the new title") // _ConsoleWindow(200, 60) ; =============================================================================================================================== ; -- This is here because writing RunDos and including a whole UDF is too much. But this is basically just _RunDos() ;Func cmd($bh6e5v_ldvar) ; RunWait(@ComSpec & " /c " & $bh6e5v_ldval) ;EndFunc Func _ConsoleClear() RunWait(@ComSpec & " /c cls") EndFunc Func _ConsoleTitle($bh6e5v_ctval) RunWait(@ComSpec & " /c title " & $bh6e5v_ctval) EndFunc Func _ConsoleWindow($bh6e5v_cwwidth, $bh6e5v_cwheight) If IsNumber($bh6e5v_cwwidth) And IsNumber($bh6e5v_cwheight) And ($bh6e5v_cwwidth > 0) And ($bh6e5v_cwheight > 0) Then RunWait(@ComSpec & " /c mode con: cols=" & $bh6e5v_cwwidth & " lines=" & $bh6e5v_cwheight) Return True Else Return False EndIf EndFunc  
      ConsoleModify.au3
    • Gowrisankar
      By Gowrisankar
      Hello everyone,
      I'm working on a task where, a PDF file is opened (in IE browser) when I click a link in a website.
      I have to read the first page of the PDF to find particular strings. Can you please share some ideas?
    • rudi
      By rudi
      Hello.
      I'm too stupid to see my mistake:
      To investigate the internal "dictionary" of TIFF files I'd like to read in the files in binary mode and to check, if there are more than one pages "in" this TIFF.
      Notepad++, "View as Hex" is presenting the first bytes as "49 49 2a 20 08 20 20 20 12" for the TIF attached to this posting
      The "TIFF Header Format" is easy:
      Offset 00h, 2 Byte = Byte Order, "II"=intel, "MM"=motorola. (I = 0x49)
      --> II
      Offset 02h, 2 Byte = Version Nr.
      Offset 04h, 4 Byte = pointer to first IFD entry
      Description of TIFF header: https://www.awaresystems.be/imaging/tiff/faq.html#q3
       

      Howto read and analyse the binary content correctly? This is my messy, not operational code:
       
      $sampleTiff="H:\daten\tif\11\11\111111.TIF" $h=FileOpen($sampleTiff,16) $content=FileRead($h) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $content = ' & $content & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console FileClose($h) $type=VarGetType($content) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $type = ' & $type & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console $ToString=BinaryToString($content) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $ToString = ' & $ToString & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console ConsoleWrite(@CRLF & @CRLF) $content=StringTrimLeft($content,2) ; cut off the leading "0x" ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $content = ' & $content & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console for $i = 1 to 8 step 8 $next=StringMid($content,$i,2) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $next = ' & $next & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console $Chr=BinaryToString($next) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Chr = ' & $Chr & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console ConsoleWrite(@CRLF & "---" & @CRLF) Next Regards, Rudi.
      111111.TIF