Skip to main content
1-Visitor
March 3, 2011
Question

Can you read from a text file in macros?

  • March 3, 2011
  • 1 reply
  • 5798 views

I have a macro that writes filenames to a text file using fwrite.

However, I don't want repeats, so want to check that the filename doesn't already exist in the text file before writing it.

I use the fwrite command but can't find a corresponding read command. Is this possible within the macros?

    1 reply

    12-Amethyst
    March 3, 2011

    I'd look into the batch command. You could run it checking if your currently held value existed in the file. Issues with this idea that you should be aware of is that each time you write a value you'll be reading the file over again. Probably not much of a performance hit for smaller lists, but could have some noticeable issues if you're lists are long.

    Another approach might be to first write your value to a variable. You'd have to do a comma delimited string, but this should suffice. You could then search the string before writing your text file. If it exists, don't write. If you look into this route, take into consideration character limitations of variables (I believe 256).

    TimSharp1-VisitorAuthor
    1-Visitor
    March 3, 2011

    Thanks for giving me more ideas - hopefully they will help.

    Yes I was wondering what the overhead might be. I have each drawing name being put into a text file and another text file that puts macro names in as they are run - intention to check which macros are being used by illustrators. So far, the files are small so there doesn't seem to be any effect on speed, but I'll see how it goes in a week or two - I might have to disable them, or have it create a new file every day.

    12-Amethyst
    March 3, 2011

    Adding to a text file shouldn't show a reduction in performance. It's only if you want to read the values to check for duplicates.

    I implemented a similar tracking element on 2-26-09. It tracks some of our macros (not all) and has been running since. It keeps the user name, macro name, illustration, and date/time it was run. At this point there are 34,692 lines in it. No one has said a word about performance degredation.

    Again, no need to worry about size other than when you are trying to check if an entry already exists.