Announcement

Collapse
No announcement yet.

Put large string in to an array. Can't remember...

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #21
    Hi Mike:

    For one thing I should not have referred to what I am doing as dealing with "large amounts" of data. It really isn't all that much in reality. I am working on a test thing to look for duplicate files. Since I have to use FindFirstFile / FindNextFile I have the opportunity to load the array elements one at a time. Also I am making an MD5 hash for each file and that takes time too.

    This is just "me fooling around" type of thing at the moment, not an actual solution to a problem. But I can say, after 35 years of doing this I have A LOT OF FILES! And copies of copies of copies!

    I don't think I am actually running into any memory limitations. I will mess with it more...

    Comment


    • #22
      RE:
      Code:
      OPEN sFileName FOR INPUT AS #hFile
      If you are going to use sequential access, you really should use the LEN=record_size option of the OPEN statement to improve performance. Basically (as documented IN PRIOR VERSIONS OF PB) ... you are basically specifying the buffer size, that is, the number of characters read at once.

      PB currently says..

      record_size Specifies the size of each record of a random access file. The default record length is 128 if not specified. If record_size is specified for a sequential file, it instructs PowerBASIC to use internal buffering to improve I/O performance.
      I typically use 1 Mb. Your mileage may vary.
      Michael Mattias
      Tal Systems (retired)
      Port Washington WI USA
      [email protected]
      http://www.talsystems.com

      Comment


      • #23
        For one thing I should not have referred to what I am doing as dealing with "large amounts" of data. It really isn't all that much in reality. I am working on a test thing to look for duplicate files. Since I have to use FindFirstFile / FindNextFile I have the opportunity to load the array elements one at a time. Also I am making an MD5 hash for each file and that takes time too.

        This is just "me fooling around" type of thing at the moment, not an actual solution to a problem. But I can say, after 35 years of doing this I have A LOT OF FILES! And copies of copies of copies!
        All you would have to save is an array of types...

        Code:
        TYPE FilesType
           FileName AS [W]STRINGZ * %MAX_PATH
           HashValue       AS  LONG|QUAD
        END TYPE
        
        ...
         LOCAL FileInfo() AS FilesType
        Within your FindFirstFile() [or DIR$ !!!] loop, open each file (you could memory map it in increments) (or just read it in chunks) or just LINE INPUT it a record at a time and run thru it a byte at a time (Don't forget to add a CRLF for each record you get with LINE INPUT!) and get a hash total. There are several hash totals you could use.. I've never done it but other members have experience with this and can offer suggestions for that code.

        Come to think of it, I'd skip using LINE INPUT because of the inconsistencies in the line termination filtered out by the LINE INPUT statement.

        Same hash value = dup file. Delete one of them.

        See how this works when you tell us WHAT you want to do rather than ask for help on a method you have already selected?

        MCM
        Michael Mattias
        Tal Systems (retired)
        Port Washington WI USA
        [email protected]
        http://www.talsystems.com

        Comment


        • #24
          Originally posted by David Clarke View Post
          For one thing I should not have referred to what I am doing as dealing with "large amounts" of data. It really isn't all that much in reality. .
          So what was the actual problem with GET$ and your 'huge" file if it''s not all that large.?


          Comment


          • #25
            So what was the actual problem with GET$ and your 'huge" file if it''s not all that large.?
            Perhaps he had not thought of getting the file contents in pieces at that time. After all, "It's the way We've always done it" ==> https://forum.powerbasic.com/forum/c...ne-it-this-way
            Michael Mattias
            Tal Systems (retired)
            Port Washington WI USA
            [email protected]
            http://www.talsystems.com

            Comment


            • #26
              Perhaps he had not thought of getting the file contents in pieces at that time.
              Go read post 1, sentence 2. He had thought of it and was specifically trying another way.
              Dale

              Comment


              • #27
                "So what was the actual problem with GET$ and your 'huge" file if it''s not all that large.?"

                Well... First I started with this:

                WHILE NOT EOF(1)
                INCR COUNTER
                WEND

                I forgot to put a LINE INPUT in the WHILE LOOP - So.... Clearly that took forever.

                Sometimes hard to see the most obvious omitions.




                Comment


                • #28
                  Michael:

                  "Same hash value = dup file. Delete one of them."

                  Excellent point!!




                  Comment


                  • #29
                    Originally posted by David Clarke View Post
                    [I]
                    I forgot to put a LINE INPUT in the WHILE LOOP - So.... Clearly that took forever.
                    WIsh I had a buck for every time I've done something similar.

                    In Access VBA, I frequently build WHILE NOT rs.EOF loops to step through a recordset.I have a bad habit of getting so involved writing the code to work with the current record that I forget to put in the the rs.MoveNext line before the WEND.


                    Comment


                    • #30
                      Stuart, I hear you! We would both be rich!

                      Comment


                      • #31
                        I see you are proceeding on this.

                        May we assume you are creating a useful utility which you plan on contributing to the forum members?

                        I am pretty sure I can guarantee all of us have duplicate files!
                        Michael Mattias
                        Tal Systems (retired)
                        Port Washington WI USA
                        [email protected]
                        http://www.talsystems.com

                        Comment


                        • #32
                          "Everything" has a command line interface (es.exe) and an SDK which can also be downloaded.
                          This produces a csv file sorted by filename (extremely quick) of all batch files which could be further processed.
                          Code:
                          FUNCTION PBMAIN AS LONG
                           'FILE NAME           PATH           SIZE
                           LOCAL pid AS LONG
                           SHELL "es.exe -name -path-column -size -export-csv out.txt *.bat"
                           pid = SHELL("notepad.exe out.txt")
                          END FUNCTION
                          Mike Doty
                          Member
                          Last edited by Mike Doty; 7 Jan 2022, 04:07 PM.

                          Comment


                          • #33
                            Originally posted by Mike Doty View Post
                            "Everything" has a command line interface (es.exe) and an SDK which can also be downloaded.
                            This produces a csv file sorted by filename (extremely quick) of all batch files which could be further processed.
                            Code:
                            FUNCTION PBMAIN AS LONG
                            'FILE NAME PATH SIZE
                            LOCAL pid AS LONG
                            SHELL "es.exe -name -path-column -size -export-csv out.txt *.bat"
                            pid = SHELL("notepad.exe out.txt")
                            END FUNCTION
                            You don't need the CLI to do it. It's actually easier in the GUI

                            File-Export on the Everything Menu (or Ctrl+S) will alse save a csv file (default extension ".efu") of whatever set you currently have displaying - and the filtering is very powerful. The drop down at th right lets you select multiple similar file types in one go
                            Click image for larger version  Name:	everythingfileter.jpg Views:	0 Size:	13.8 KB ID:	813429

                            If you export without any filters, you get all the files and folders ( ordered with folders first)


                            Click image for larger version  Name:	everything2.jpg Views:	0 Size:	95.2 KB ID:	813430

                            And yes, it's extremely fast - there's no way you will get anywhere near its speed with your own code since it is not scanning the disk, it is just exporting its cache of the MFT.

                            Comment


                            • #34
                              Originally posted by David Clarke View Post
                              Hi Mike:

                              For one thing I should not have referred to what I am doing as dealing with "large amounts" of data. It really isn't all that much in reality. I am working on a test thing to look for duplicate files. Since I have to use FindFirstFile / FindNextFile I have the opportunity to load the array elements one at a time. Also I am making an MD5 hash for each file and that takes time too.

                              This is just "me fooling around" type of thing at the moment, not an actual solution to a problem. But I can say, after 35 years of doing this I have A LOT OF FILES! And copies of copies of copies!

                              I don't think I am actually running into any memory limitations. I will mess with it more...
                              File size,full path and name
                              So many options: https://www.voidtools.com/support/everything/searching/

                              To install Command line interface scroll down to Command Line Interface (es.exe is in the .zip file)
                              https://www.voidtools.com/downloads/

                              This gives a lot of control since "out.csv" could be loaded into a listbox.
                              SHELL "es.exe -sort-descending /os -size -full-path-and-name -export-csv out.csv " + sSearch

                              Code:
                              FUNCTION PBMAIN AS LONG
                               LOCAL pid     AS DWORD
                               LOCAL sSearch AS STRING
                               sSearch = "size:0 *.bas"  '0-length bas files
                               sSearch = "*.bas"
                               DO
                                sSearch = INPUTBOX$("prompt","Title",sSearch)
                                IF LEN(sSearch) = 0  THEN EXIT DO
                                KILL "out.csv"
                                SHELL "es.exe -sort-descending /os -size -full-path-and-name -export-csv out.csv " + sSearch
                                IF ISFILE("out.csv") THEN
                                  pid??? = SHELL( "notepad out.csv")
                                ELSE
                                  BEEP
                                END IF
                               LOOP
                              
                              END FUNCTION

                              Comment


                              • #35
                                I see nothing offered by all you Everything-o-philes that suggests it would help Mr. Clarke with his challenge of identifying duplicates.

                                Besides, simply downloading something - not writing it yourself - is not emotionally satisfying at all.
                                Michael Mattias
                                Tal Systems (retired)
                                Port Washington WI USA
                                [email protected]
                                http://www.talsystems.com

                                Comment


                                • #36
                                  Originally posted by Michael Mattias View Post
                                  I see nothing offered by all you Everything-o-philes that suggests it would help Mr. Clarke with his challenge of identifying duplicates.
                                  Other than a very quick and easy way to get his "database" of hundreds of thousands of filenames and their sizes rather than writing code to do a time consuming search through his disks.

                                  Originally posted by Michael Mattias View Post
                                  IBesides, simply downloading something - not writing it yourself - is not emotionally satisfying at all
                                  Note from Post# 12 that he is already using Everything. If you've got the tool already running on your computer, why not use it?

                                  From his sttatement "Since I have to use FindFirstFile / FindNextFile", it would appear that he was not aware that his existing software could do the task for him much more simply.

                                  Comment


                                  • #37
                                    Michael: "May we assume you are creating a useful utility which you plan on contributing to the forum members?"

                                    Absolutely! However, what I have right now are a bunch of separate programs that each do some of what I need.

                                    One of the programs that is quite handy is listed below. It uses exiftool.ext to return information about the file. You need to have exiftool.exe in the same directory as this program.
                                    This is just a demo. But it shows some very useful information. This is what it told me about a test.jpg file:

                                    Code:
                                    ExifTool Version Number : 12.13
                                    File Name : Test_2.jpg
                                    Directory : C:/EXIFTOOL_TOOL
                                    File Size : 2.9 MiB
                                    File Modification Date/Time : 2021:01:02 21:53:49-05:00
                                    File Access Date/Time : 2022:01:09 14:51:44-05:00
                                    File Creation Date/Time : 2021:01:11 17:04:53-05:00
                                    File Permissions : rw-rw-rw-
                                    File Type : JPEG
                                    File Type Extension : jpg
                                    MIME Type : image/jpeg
                                    Exif Byte Order : Big-endian (Motorola, MM)
                                    Photometric Interpretation : RGB
                                    Make : Apple
                                    Camera Model Name : iPhone 6
                                    Orientation : Horizontal (normal)
                                    Samples Per Pixel : 3
                                    X Resolution : 72
                                    Y Resolution : 72
                                    Resolution Unit : inches
                                    Software : Adobe Photoshop 22.1 (Windows)
                                    Modify Date : 2021:01:02 21:53:47
                                    Y Cb Cr Positioning : Centered
                                    XP Title :
                                    XP Subject :
                                    Exposure Time : 1/30
                                    F Number : 2.2
                                    Exposure Program : Program AE
                                    ISO : 100
                                    Exif Version : 0221
                                    Date/Time Original : 2016:08:19 16:23:33
                                    Create Date : 2016:08:19 16:23:33
                                    Components Configuration : Y, Cb, Cr, -
                                    Shutter Speed Value : 1/30
                                    Aperture Value : 2.2
                                    Brightness Value : 2.346241458
                                    Exposure Compensation : 0
                                    Metering Mode : Multi-segment
                                    Flash : Off, Did not fire
                                    Focal Length : 4.2 mm
                                    Subject Area : 1812 1031 159 159
                                    Sub Sec Time Original : 00
                                    Sub Sec Time Digitized : 00
                                    Flashpix Version : 0100
                                    Color Space : sRGB
                                    Exif Image Width : 3264
                                    Exif Image Height : 2448
                                    Sensing Method : One-chip color area
                                    Scene Type : Directly photographed
                                    Exposure Mode : Auto
                                    White Balance : Auto
                                    Focal Length In 35mm Format : 29 mm
                                    Scene Capture Type : Standard
                                    Lens Info : 4.15mm f/2.2
                                    Lens Make : Apple
                                    Lens Model : iPhone 6 back camera 4.15mm f/2.2
                                    Padding : (Binary data 2060 bytes, use -b option to extract)
                                    Offset Schema : 0
                                    GPS Version ID : 2200
                                    GPS Latitude Ref : North
                                    GPS Longitude Ref : West
                                    GPS Measure Mode : 2-Dimensional Measurement
                                    GPS Speed Ref : km/h
                                    GPS Speed : 0
                                    GPS Img Direction Ref : True North
                                    GPS Img Direction : 235.9603524
                                    GPS Dest Bearing Ref : True North
                                    GPS Dest Bearing : 235.9603524
                                    GPS Horizontal Positioning Error: 65 m
                                    Compression : JPEG (old-style)
                                    Thumbnail Offset : 5386
                                    Thumbnail Length : 6386
                                    Current IPTC Digest : 16dcb15c16e8f1d3c60ff891ffcfd2e0
                                    Coded Character Set : UTF8
                                    Application Record Version : 0
                                    Time Created : 16:23:33+00:00
                                    IPTC Digest : 16dcb15c16e8f1d3c60ff891ffcfd2e0
                                    Displayed Units X : inches
                                    Displayed Units Y : inches
                                    Print Style : Centered
                                    Print Position : 0 0
                                    Print Scale : 1
                                    Global Angle : 30
                                    Global Altitude : 30
                                    URL List :
                                    Slices Group Name : 0000129013
                                    Num Slices : 1
                                    Pixel Aspect Ratio : 1
                                    Photoshop Thumbnail : (Binary data 6386 bytes, use -b option to extract)
                                    Has Real Merged Data : Yes
                                    Writer Name : Adobe Photoshop
                                    Reader Name : Adobe Photoshop 2021
                                    Photoshop Quality : 12
                                    Photoshop Format : Progressive
                                    Progressive Scans : 3 Scans
                                    XMP Toolkit : Adobe XMP Core 6.0-c003 79.164527, 2020/10/15-17:48:32
                                    Creator Tool : Tag That Photo
                                    Metadata Date : 2021:01:02 21:53:47-05:00
                                    Format : image/jpeg
                                    Date Created : 2016:08:19 16:23:33
                                    Legacy IPTC Digest : 94334D9254870840C20BF8473D7CF3F7
                                    Color Mode : RGB
                                    ICC Profile Name : sRGB IEC61966-2.1
                                    Instance ID : xmp.iid:116b7e6c-3f4c-2743-bb88-7e1a44f8fa9a
                                    Document ID : adobe:docid:photoshop:5e65f724-babe-8543-90d8-eef80ec6a8ff
                                    Original Document ID : CB0B750B8624854DA7D0D2FAFF4F906F
                                    Lens : iPhone 6 back camera 4.15mm f/2.2
                                    Subject :
                                    Person In Image : Emma
                                    Region Applied To Dimensions W : 3264
                                    Region Applied To Dimensions H : 2448
                                    Region Applied To Dimensions Unit: pixel
                                    Region Name : Emma
                                    Region Type : Face
                                    Region Area X : 0.551164215686274
                                    Region Area Y : 0.402777777777778
                                    Region Area W : 0.0542279411764706
                                    Region Area H : 0.0886437908496732
                                    Region Area Unit : normalized
                                    Region Rectangle : 0.524050245098039, 0.358455882352941, 0.0542279411764706, 0.0886437908496732
                                    Region Person Display Name : Emma
                                    History Action : saved, saved
                                    History Instance ID : xmp.iid:a6884ad4-6543-9b4d-92bb-e745b1c363c2, xmp.iid:116b7e6c-3f4c-2743-bb88-7e1a44f8fa9a
                                    History When : 2021:01:02 21:53:47-05:00, 2021:01:02 21:53:47-05:00
                                    History Software Agent : Adobe Photoshop 22.1 (Windows), Adobe Photoshop 22.1 (Windows)
                                    History Changed : /, /
                                    Profile CMM Type : Linotronic
                                    Profile Version : 2.1.0
                                    Profile Class : Display Device Profile
                                    Color Space Data : RGB
                                    Profile Connection Space : XYZ
                                    Profile Date Time : 1998:02:09 06:49:00
                                    Profile File Signature : acsp
                                    Primary Platform : Microsoft Corporation
                                    CMM Flags : Not Embedded, Independent
                                    Device Manufacturer : Hewlett-Packard
                                    Device Model : sRGB
                                    Device Attributes : Reflective, Glossy, Positive, Color
                                    Rendering Intent : Perceptual
                                    Connection Space Illuminant : 0.9642 1 0.82491
                                    Profile Creator : Hewlett-Packard
                                    Profile ID : 0
                                    Profile Copyright : Copyright (c) 1998 Hewlett-Packard Company
                                    Profile Description : sRGB IEC61966-2.1
                                    Media White Point : 0.95045 1 1.08905
                                    Media Black Point : 0 0 0
                                    Red Matrix Column : 0.43607 0.22249 0.01392
                                    Green Matrix Column : 0.38515 0.71687 0.09708
                                    Blue Matrix Column : 0.14307 0.06061 0.7141
                                    Device Mfg Desc : IEC http://www.iec.ch
                                    Device Model Desc : IEC 61966-2.1 Default RGB colour space - sRGB
                                    Viewing Cond Desc : Reference Viewing Condition in IEC61966-2.1
                                    Viewing Cond Illuminant : 19.6445 20.3718 16.8089
                                    Viewing Cond Surround : 3.92889 4.07439 3.36179
                                    Viewing Cond Illuminant Type : D50
                                    Luminance : 76.03647 80 87.12462
                                    Measurement Observer : CIE 1931
                                    Measurement Backing : 0 0 0
                                    Measurement Geometry : Unknown
                                    Measurement Flare : 0.999%
                                    Measurement Illuminant : D65
                                    Technology : Cathode Ray Tube Display
                                    Red Tone Reproduction Curve : (Binary data 2060 bytes, use -b option to extract)
                                    Green Tone Reproduction Curve : (Binary data 2060 bytes, use -b option to extract)
                                    Blue Tone Reproduction Curve : (Binary data 2060 bytes, use -b option to extract)
                                    DCT Encode Version : 100
                                    APP14 Flags 0 : [14]
                                    APP14 Flags 1 : (none)
                                    Color Transform : YCbCr
                                    Image Width : 3264
                                    Image Height : 2448
                                    Encoding Process : Progressive DCT, Huffman coding
                                    Bits Per Sample : 8
                                    Color Components : 3
                                    Y Cb Cr Sub Sampling : YCbCr4:4:4 (1 1)
                                    Aperture : 2.2
                                    Image Size : 3264x2448
                                    Lens ID : iPhone 6 back camera 4.15mm f/2.2
                                    Megapixels : 8.0
                                    Scale Factor To 35 mm Equivalent: 7.0
                                    Shutter Speed : 1/30
                                    Create Date : 2016:08:19 16:23:33.00
                                    Date/Time Original : 2016:08:19 16:23:33.00
                                    Thumbnail Image : (Binary data 6386 bytes, use -b option to extract)
                                    GPS Latitude : 43 deg 37' 46.31" N
                                    GPS Longitude : 70 deg 19' 42.71" W
                                    Date/Time Created : 2016:08:19 16:23:33+00:00
                                    Circle Of Confusion : 0.004 mm
                                    Field Of View : 63.7 deg
                                    Focal Length : 4.2 mm (35 mm equivalent: 29.0 mm)
                                    GPS Position : 43 deg 37' 46.31" N, 70 deg 19' 42.71" W
                                    Hyperfocal Distance : 1.82 m
                                    Light Value : 7.2

                                    Code:
                                    #COMPILE EXE
                                    #DIM ALL
                                    #INCLUDE "win32api.inc"
                                    
                                    %IDC_TEXTBOX1 = 121
                                    
                                    %HANDLE_FLAG_INHERIT = &H00000001
                                    %BUFFERSIZE = 32768
                                    
                                    $ProgName = "exiftool.exe"
                                    $ProgOptions = "-stay_open True [email protected] -"
                                    $Ready = "{ready}" + $CRLF
                                    
                                    GLOBAL hChildStdInRead AS DWORD
                                    GLOBAL hChildStdInWrite AS DWORD
                                    GLOBAL hChildStdOutRead AS DWORD
                                    GLOBAL hChildStdOutWrite AS DWORD
                                    GLOBAL hChildStdErrRead AS DWORD
                                    GLOBAL hChildStdErrWrite AS DWORD
                                    
                                    GLOBAL oldProc AS LONG
                                    
                                    '====================================================================
                                    FUNCTION PBMAIN()AS LONG
                                    LOCAL hDlg AS LONG
                                    LOCAL dwRC AS DWORD
                                    LOCAL dwFont AS DWORD
                                    
                                    ' Start the exiftool process
                                    dwRC = Init_exiftool()
                                    
                                    IF dwRC <> %TRUE THEN
                                    MessageBox(%NULL,"Child process exiftool failed to initialize","Error starting exiftool",%MB_OK)
                                    FUNCTION = %FALSE
                                    EXIT FUNCTION
                                    END IF
                                    
                                    DIALOG NEW 0,"Drag and drop file(s) or folder(s) to see any supported meta data",,, 800, 600, %WS_SYSMENU OR %WS_CAPTION, TO hDlg
                                    
                                    CONTROL ADD TEXTBOX, hDlg, %IDC_TEXTBOX1, "", 5, 5, 790, 590, %WS_VSCROLL OR %ES_MULTILINE, %WS_EX_ACCEPTFILES
                                    
                                    ' Use a fixed width font
                                    FONT NEW "COURIER" TO dwFont
                                    CONTROL SET FONT hDlg, %IDC_TEXTBOX1, dwFont
                                    
                                    DIALOG SHOW MODAL hDlg, CALL DlgProc
                                    
                                    FONT END dwFont
                                    
                                    'Close exiftool
                                    WriteToPipe("-stay_open" + $CRLF)
                                    WriteToPipe("False" + $CRLF)
                                    
                                    SLEEP 2000
                                    
                                    CloseHandle(hChildStdInRead)
                                    CloseHandle(hChildStdInWrite)
                                    CloseHandle(hChildStdOutRead)
                                    CloseHandle(hChildStdOutWrite)
                                    CloseHandle(hChildStdErrRead)
                                    CloseHandle(hChildStdErrWrite)
                                    
                                    END FUNCTION
                                    
                                    '====================================================================
                                    CALLBACK FUNCTION DlgProc
                                    SELECT CASE CBMSG
                                    CASE %WM_INITDIALOG
                                    ' oldProc will be same for all standard controls of same class, so..
                                    oldProc = SetWindowLong(GetDlgItem(CB.HNDL, %IDC_TEXTBOX1), %GWL_WNDPROC, CODEPTR(DragDropProc))
                                    END SELECT
                                    
                                    END FUNCTION
                                    
                                    '====================================================================
                                    CALLBACK FUNCTION DragDropProc
                                    LOCAL c AS LONG, zFile AS ASCIIZ * 260, sMetaData AS STRING
                                    
                                    SELECT CASE AS LONG CB.MSG
                                    CASE %WM_DROPFILES
                                    c = DragQueryFile (CB.WPARAM, -1, BYVAL 0, 0)
                                    FOR c = 0 TO c - 1 ' if several files were dropped
                                    DragQueryFile CB.WPARAM, c, zFile, SIZEOF(zFile)
                                    WriteToPipe(zFile + $CRLF)
                                    NEXT
                                    WriteToPipe("-execute" + $CRLF)
                                    sMetaData = ReadFromPipe()
                                    SetWindowText CB.HNDL, BYVAL STRPTR(sMetaData)
                                    DragFinish CB.WPARAM
                                    
                                    END SELECT
                                    
                                    FUNCTION = CallWindowProc(oldProc, CB.HNDL, CB.MSG, CB.WPARAM, CB.LPARAM)
                                    END FUNCTION
                                    
                                    FUNCTION DisplayError(sErrMsg AS STRING,BYVAL LastError AS DWORD) AS LONG
                                    
                                    ' Format a readable error message and display a message box
                                    LOCAL pzMessage AS ASCIIZ POINTER
                                    
                                    FormatMessage(%FORMAT_MESSAGE_ALLOCATE_BUFFER OR _
                                    %FORMAT_MESSAGE_FROM_SYSTEM OR _
                                    %FORMAT_MESSAGE_IGNORE_INSERTS, _
                                    BYVAL %NULL,LastError,MAKELANGID(%LANG_NEUTRAL,%SUBLANG_DEFAULT), _
                                    BYVAL VARPTR(pzMessage),0,BYVAL %NULL )
                                    
                                    sErrMsg += " failed with error" + STR$(LastError) + $CRLF + @pzMessage
                                    LocalFree(pzMessage)
                                    MessageBox(%NULL,BYVAL STRPTR(sErrMsg),"Error",%MB_OK)
                                    
                                    END FUNCTION
                                    
                                    FUNCTION Init_exiftool() AS DWORD
                                    
                                    LOCAL dwRC AS DWORD
                                    LOCAL SecurityAttribute AS SECURITY_ATTRIBUTES
                                    LOCAL ProcessInfo AS PROCESS_INFORMATION
                                    LOCAL StartupInf AS STARTUPINFO
                                    LOCAL LastError AS DWORD
                                    LOCAL zCommandLine AS ASCIIZ * %MAX_PATH
                                    
                                    ' Executable exiftool.exe is expected to be in the same folder as this executable
                                    zCommandLine = EXE.PATH$ + $ProgName
                                    IF ISFALSE ISFILE(zCommandLine) THEN
                                    MessageBox(%NULL,"Missing exiftool.exe","Error - Missing Executable",%MB_OK)
                                    FUNCTION = %FALSE
                                    EXIT FUNCTION
                                    END IF
                                    
                                    ' Set the bInheritHandle flag so pipe handles are inherited
                                    SecurityAttribute.nLength = SIZEOF(SECURITY_ATTRIBUTES)
                                    SecurityAttribute.bInheritHandle = %TRUE
                                    SecurityAttribute.lpSecurityDescriptor = %NULL
                                    
                                    ' Create a pipe for exiftool STDIN
                                    IF CreatePipe(hChildStdInRead,hChildStdInWrite,SecurityAttribute,BYVAL 0) = %FALSE THEN
                                    LastError = GetLastError()
                                    DisplayError("E01 StdIn CreatePipe",LastError)
                                    FUNCTION = %FALSE
                                    EXIT FUNCTION
                                    END IF
                                    
                                    ' Ensure the write handle to the pipe for STDIN is not inherited
                                    IF SetHandleInformation(hChildStdInWrite,%HANDLE_FLAG_INHERIT,0) = %FALSE THEN
                                    LastError = GetLastError()
                                    DisplayError("E02 Stdin SetHandleInformation",LastError)
                                    FUNCTION = %FALSE
                                    EXIT FUNCTION
                                    END IF
                                    
                                    ' Create a pipe for exiftool STDOUT
                                    IF CreatePipe(hChildStdOutRead,hChildStdOutWrite,SecurityAttribute,BYVAL 0) = %FALSE THEN
                                    LastError = GetLastError()
                                    DisplayError("E03 StdOutRd CreatePipe",LastError)
                                    FUNCTION = %FALSE
                                    EXIT FUNCTION
                                    END IF
                                    
                                    ' Ensure the read handle to the pipe for STDOUT is not inherited
                                    IF SetHandleInformation(hChildStdOutRead,%HANDLE_FLAG_INHERIT,BYVAL 0) = %FALSE THEN
                                    LastError = GetLastError()
                                    DisplayError("E04 StdOut SetHandleInformation",LastError)
                                    FUNCTION = %FALSE
                                    EXIT FUNCTION
                                    END IF
                                    
                                    ' Create a pipe for exiftool STDERR
                                    IF CreatePipe(hChildStdErrRead,hChildStdErrWrite,SecurityAttribute,BYVAL 0) = %FALSE THEN
                                    LastError = GetLastError()
                                    DisplayError("E05 StdErrRd CreatePipe",LastError)
                                    FUNCTION = %FALSE
                                    EXIT FUNCTION
                                    END IF
                                    
                                    ' Ensure the read handle to the pipe for STDERR is not inherited
                                    IF SetHandleInformation(hChildStdErrRead,%HANDLE_FLAG_INHERIT,BYVAL 0) = %FALSE THEN
                                    LastError = GetLastError()
                                    DisplayError("E06 StdErr SetHandleInformation",LastError)
                                    FUNCTION = %FALSE
                                    EXIT FUNCTION
                                    END IF
                                    
                                    ' STARTUPINFO structure - This structure specifies the STDIN, STDOUT and STDERR handles for redirection
                                    StartupInf.cb = SIZEOF(STARTUPINFO)
                                    StartupInf.hStdInput = hChildStdInRead
                                    StartupInf.hStdOutput = hChildStdOutWrite
                                    StartupInf.hStdError = hChildStdErrWrite
                                    StartupInf.dwFlags = %STARTF_USESTDHANDLES
                                    
                                    ' Create the exiftool child process with program options
                                    zCommandLine += " " + $ProgOptions
                                    dwRC = CreateProcess(BYVAL %NULL, _ ' Application Name
                                    zCommandLine, _ ' Command line
                                    BYVAL %NULL, _ ' Process security attributes
                                    BYVAL %NULL, _ ' Primary thread security attributes
                                    %TRUE, _ ' Handles are inherited
                                    %CREATE_NO_WINDOW, _ ' Creation flags
                                    BYVAL %NULL, _ ' Use parent's environment
                                    BYVAL %NULL, _ ' Use parent's current directory
                                    StartupInf, _ ' STARTUPINFO pointer
                                    ProcessInfo) _ ' Receives PROCESS_INFORMATION
                                    
                                    LastError = GetLastError()
                                    IF dwRC = %FALSE THEN
                                    DisplayError("E07 CreateProcess",LastError)
                                    FUNCTION = %FALSE
                                    EXIT FUNCTION
                                    ELSE
                                    ' Close handles to the exiftool process and its primary thread...they aren't needed
                                    CloseHandle(ProcessInfo.hProcess)
                                    CloseHandle(ProcessInfo.hThread)
                                    FUNCTION = %TRUE
                                    END IF
                                    
                                    END FUNCTION
                                    
                                    FUNCTION WriteToPipe(sCmd AS STRING) AS DWORD
                                    
                                    ' Write to the child's STDIN
                                    LOCAL dwRC AS DWORD
                                    LOCAL WrittenCount AS DWORD
                                    LOCAL LastError AS DWORD
                                    
                                    DO
                                    dwRC = WriteFile(hChildStdInWrite,BYVAL STRPTR(sCmd),BYVAL LEN(sCmd),WrittenCount,BYVAL %NULL)
                                    IF dwRC = %TRUE THEN
                                    EXIT DO
                                    ELSE
                                    LastError = GetLastError()
                                    DisplayError("E08 WriteFile",LastError)
                                    FUNCTION = %FALSE
                                    EXIT FUNCTION
                                    END IF
                                    LOOP
                                    
                                    END FUNCTION
                                    
                                    FUNCTION ReadFromPipe() AS STRING
                                    
                                    ' Read from the child's STDOUT
                                    LOCAL dwRC AS DWORD
                                    LOCAL dwLEN_Ready AS DWORD
                                    LOCAL ReadCount AS DWORD
                                    LOCAL LastError AS DWORD
                                    LOCAL sBuffer AS STRING
                                    LOCAL sFuncReturn AS STRING
                                    
                                    dwLEN_Ready = LEN($Ready)
                                    sBuffer = SPACE$(%BUFFERSIZE)
                                    
                                    DO
                                    dwRC = ReadFile(hChildStdOutRead,BYVAL STRPTR(sBuffer),BYVAL LEN(sBuffer),ReadCount,BYVAL %NULL)
                                    IF dwRC = %TRUE THEN
                                    sFuncReturn += LEFT$(sBuffer,ReadCount)
                                    ELSE
                                    LastError = GetLastError()
                                    DisplayError("E09 ReadFile",LastError)
                                    FUNCTION = "{error}"
                                    EXIT FUNCTION
                                    END IF
                                    LOOP UNTIL RIGHT$(sFuncReturn,dwLEN_Ready) = $Ready
                                    FUNCTION = LEFT$(sFuncReturn,LEN(sFuncReturn) - dwLEN_Ready)
                                    
                                    END FUNCTION
                                    
                                    FUNCTION GetExif(sFile AS STRING) AS STRING
                                    
                                    ' Wrapper function to return exif data in a single function call
                                    WriteToPipe(sFile + $CRLF)
                                    WriteToPipe("-execute" + $CRLF)
                                    FUNCTION = ReadFromPipe()
                                    
                                    END FUNCTION

                                    Comment


                                    • #38
                                      This is what it told me about a test.jpg file:
                                      Sheesh. I wouldn't want to know that much about a potential wife.
                                      Michael Mattias
                                      Tal Systems (retired)
                                      Port Washington WI USA
                                      [email protected]
                                      http://www.talsystems.com

                                      Comment


                                      • #39
                                        "Sheesh. I wouldn't want to know that much about a potential wife." = Ha! I know it's a lot of info!

                                        Comment

                                        Working...
                                        X