(Again sorry for a delay.)
dbenham wrote:Here is a small variation on Aacini's recommendation, using powers of two. The following will produce a space variable containing 1024 spaces, and delayed expansion is only temporarily enabled:
Code: Select all
set "space= "
setlocal enableDelayedExpansion
for /l %%N in (1 1 10) do set "space=!space!!space!"
endlocal & set "space=%space%"
This only needs to be done once. As others have suggested, from that point on you can simply use a substring expansion to get any length up to 1024. For example
%space:-123% will yield 123 spaces.
Dave Benham
I will use this. I like this solution.
Squashman wrote:Are the file offset and the record length included in the entire record length?
This information is really not neccessary because all I wanted to know is how to get the desired number of spaces.
@Aacini (not to copy your long post):
I prefer this method of not using another 'index' file: I can search for desired record by different strings (logical AND). And when all the strings are found in ONE record then I process that record(s). I read this temporary file record by record and instantly get the record offset and it's length.
I don't reuse deleted records. I either modify/delete existing records or add new records. I also have a 'index rebuild' subprogram to recalculate record offsets and record lengths.
I must delete records I don't need (I cannot use 'deleted' mark) - the record that should be deleted is no longer valid. If I keep this information I can always find it (because I use FINDSTR with 1 (or more) input strings).
For example, actual file can look like this:
Code: Select all
0; 95;_FIELD;STREET;LEVEL;APP_NUM;OWNER;LOCATION;SERIAL_NUM;PHONE;BUILDING_MGR;COMMENT;
97;102;Field1;Brown street;+00;0001;John Doe;Hallway;34054791;1-800-1234567;Building Manager;#;
201; 99;Field1;Brown street;+00;0001;John Doe;Room;34054792;1-800-1234567;Building Manager;#;
302;104;Field1;Brown street;+00;0002;Susan Doe;Bathroom;34054700;1-800-2345678;Building Manager;#;
408;103;Field1;Brown street;+00;0002;Susan Doe;Kitchen;34054701;1-800-2345678;Building Manager;#;
I use FINDSTR to find the record. Though the main 'key' in this file is SERIAL_NUMBER I can actually find the records in this way:
Let's say I want to find "John" for whom I know lives at "Brown street":
1. First I do a FINDSTR for %1: John into a temporary file
2. Then I do FINDSTR for %2: street from the temporary file into another temporary file
3. Rename another temporary file to the first temporary file and do more searches if neccessary. If not then I process this file record by record (of course with FOR /F to separate fields into variables etc...)
4. If I want to update/delete the record and if the new record length would not be the same I have to write all spaces when the actual data is (so I don't have trailing spaces in this record). When updating the data I then write the new record at the end of the file.
Working example was in another post (
viewtopic.php?p=34025#p34025)
Thank you all.
Saso