5 Replies Latest reply on Mar 15, 2009 3:36 PM by Chunick

    Read the content of a file when it changes

    Level 7
      Hello:
      I need to read from a file (txt, mdb... ) only when the content in it
      changes. Can you guide me about this topic?
      Do I need any Xtras or call a DLL?
      Thank you very much


        • 1. Re: Read the content of a file when it changes
          Nanomedia Level 1
          quote:

          Originally posted by: Arielle
          I need to read from a file (txt, mdb... ) only when the content in it changes.


          To see if something is changed, you must read that file first of all.

          But if that file is very big, the application which is involved can write another small file containing the last modify date.
          You can read the small file and compare the dates.
          • 2. Re: Read the content of a file when it changes
            Chunick Level 3
            It really depends on what type of file; txt files are easy using the built-in FileIO Xtra. An mdb file would require an Xtra. The Mile Hight Table O' Products http://www.deansdirectortutorials.com/MileHighTable/ can help you find an Xtra for you specific needs.

            As for reading it only when it changes... well, that's an interesting problem since you couldn't know if the information in it changed unless you kept the state of that information somewhere... there are several ways I can think that would probably work, but you should probably be a bit more specific in describing what you're trying to accomplish - that should help with a more specific and detailed answer.
            • 3. Read the content of a file when it changes
              Chunick Level 3
              quote:

              Originally posted by: Nanomedia
              quote:

              Originally posted by: Arielle
              I need to read from a file (txt, mdb... ) only when the content in it changes.


              To see if something is changed, you must read that file first of all.

              But if that file is very big, the application which is involved can write another small file containing the last modify date.
              You can read the small file and compare the dates.


              The problem with keeping the last modify date in a file is that you still need to compare that date to some other date... let's look at a file on a computer that contains a 'last modified' date... I want to know if it's changed - but I need another piece of information - I need to either know when the previous 'last modified' date was, or I need to test against a general set of parameters such as, "if the file's 'last modified' date is within the current date and 3 days ago, then..."

              The only way to compare if data has changed is to have the original data to compare against the new data - and that almost always involves reading the two pieces of data/files - or a faster method is to create a hash of the original or previous copy to compare against a hash of the current copy. For this you can use MD5 or SHA checksum hashes. Valentin has a nice Xtra that can do this: http://staff.dasdeck.de/valentin/xtras/crypto/ , and it would still involve reading both pieced of data/files at least once to generate the hashes.
              • 4. Re: Read the content of a file when it changes
                Nanomedia Level 1
                quote:

                Originally posted by: Chunick
                quote:

                Originally posted by: Nanomedia
                To see if something is changed, you must read that file first of all.



                The problem with keeping the last modify date in a file is that you still need to compare that date to some other date... let's look at a file on a computer that contains a 'last modified' date... I want to know if it's changed - but I need another piece of information - I need to either know when the previous 'last modified' date was, or I need to test against a general set of parameters such as, "if the file's 'last modified' date is within the current date and 3 days ago, then..."

                The only way to compare if data has changed is to have the original data to compare against the new data - and that almost always involves reading the two pieces of data/files - or a faster method is to create a hash of the original or previous copy to compare against a hash of the current copy. For this you can use MD5 or SHA checksum hashes. Valentin has a nice Xtra that can do this: http://staff.dasdeck.de/valentin/xtras/crypto/ , and it would still involve reading both pieced of data/files at least once to generate the hashes.


                First time you must download them both.
                Next time you have to download only the very small text file containing the last modified date.

                And btw: you cannot use the MD5 or SHA approach if the big file is hosted on another server.
                Valentin's xtra is not shockwave safe.
                • 5. Re: Read the content of a file when it changes
                  Chunick Level 3
                  quote:

                  Originally posted by: Nanomedia
                  quote:

                  Originally posted by: Chunick
                  quote:

                  Originally posted by: Nanomedia
                  To see if something is changed, you must read that file first of all.



                  The problem with keeping the last modify date in a file is that you still need to compare that date to some other date... let's look at a file on a computer that contains a 'last modified' date... I want to know if it's changed - but I need another piece of information - I need to either know when the previous 'last modified' date was, or I need to test against a general set of parameters such as, "if the file's 'last modified' date is within the current date and 3 days ago, then..."

                  The only way to compare if data has changed is to have the original data to compare against the new data - and that almost always involves reading the two pieces of data/files - or a faster method is to create a hash of the original or previous copy to compare against a hash of the current copy. For this you can use MD5 or SHA checksum hashes. Valentin has a nice Xtra that can do this: http://staff.dasdeck.de/valentin/xtras/crypto/ , and it would still involve reading both pieced of data/files at least once to generate the hashes.


                  First time you must download them both.
                  Next time you have to download only the very small text file containing the last modified date.

                  And btw: you cannot use the MD5 or SHA approach if the big file is hosted on another server.
                  Valentin's xtra is not shockwave safe.


                  ...I'd suggest re-reading the OP's post; the OP never mentioned servers or shockwave. Maybe we should ask the OP that question as it's a good one - otherwise you're getting a bit ahead of yourself, there.