WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Binary Functions

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Using Binary Functions to Edit INI Files

Keywords:    INI files IniWritePvt

Question:

I have an interesting bug and/or problem:

I am basically trying to edit the *headers* in an INI file, without recreating them anew. For speed and just plain old practice, I decided to use the binary functions to search and replace. Based on one changed variable, however, I need to change several different headers. Therefore, I call my search and replace function 2 or 3 times to operate on a single file.

My problem seems to be: if I run my program and do the replace, I get different results for the same input. However, if I have the debug(@on) in my program near my possibly offending code, even if I immediately hit the RUN button, the code works every time I have tried it. My best guess so far is that the Write hasn't taken place before the next read occurs - but I have inserted 10 second delays, and gotten almost identical results. (w/debug it works, w/o debug it sometimes works, or does one set of replaces) I'd like to stick to the binary s&r if I can,though I'd consider switching to FileRead /write if I had to.

Answer:

Here are some points to consider:
  1. INI Files are tricky. The system caches them and writes them to disk in its own sweet time if you or any program you run is using the IniWritePvt functions (aka Windows API SetPrivateProfileString"). If there is a write pending, and you modify the file, then windows updates it.....

    Try adding:

    IniWritePvt("","","","yourinifilename.ini")
    
    to the top of the script to force a "flush" of any cached copies to disk. The three null parameters is a hint to windows to flush it out of cache.

  2. For debugging, try adding a bunch of:
    BinaryWrite(xx,"file1.txt")
    
    (then file2.txt file3.txt, etc)

    so you can see the step by step progress of your changes. And see if some disappear or something.

P.S. I don't think FileRead/Write will change the problem.
Article ID:   W12739
Filename:   Use Binary Functions to Edit INI Files.txt
File Created: 1999:04:15:16:49:18
Last Updated: 1999:04:15:16:49:18