• Support
  • Articles
  • Resources
  • Products

Copy file handles

Moderator: boris

1 postPage 1 of 1

stevo
Newbie

Posts:
19
Joined: Tue Oct 15, 2013 11:08 pm
by stevo » Tue Aug 12, 2014 1:51 am
Useful for when you want to read/write from/to multiple files within a script:

Code: Select all

  1. CLOSETT
  2. ; This is to test copying file handles
  3.  
  4. FileOpen fh_test1 'C:\scripts\Dev\testfile1.txt' 0 ; change to your own location
  5. FileOpen fh_test2 'C:\scripts\Dev\testfile2.txt' 0 ; change to your own location
  6. FileOpen fh_test3 'C:\scripts\Dev\testfile3.txt' 0 ; change to your own location
  7.  
  8. FileWriteLn fh_test1 'String1'
  9. FileWriteLn fh_test2 'String2'
  10. FileWriteLn fh_test3 'String3'
  11.  
  12. fh_generic = fh_test1 ; copy the file handle
  13. messagebox fh_generic 'Is fh_generic valid?'
  14. FileWriteLn fh_generic 'StringA' ; write to file using copy of file handle instead of original file handle
  15. fh_generic = fh_test2 ; copy the file handle
  16. messagebox fh_generic 'Is fh_generic valid?'
  17. FileWriteLn fh_generic 'StringA' ; write to file using copy of file handle instead of original file handle
  18. fh_generic = fh_test3 ; copy the file handle
  19. messagebox fh_generic 'Is fh_generic valid?'
  20. FileWriteLn fh_generic 'StringA' ; write to file using copy of file handle instead of original file handle
  21.  
  22. FileClose fh_test1
  23. FileClose fh_test2
  24. FileClose fh_test3
  25.  
  26. ; Each file opened above should contain 2 lines:
  27. ; Line 1 = 'StringX' where 'X' is the respective file number
  28. ; Line 2 = 'StringA' - literal string


Hope this inspires all you 'scriptics'! ;)
Comments welcome.

1 postPage 1 of 1

Users browsing this forum: No registered users
cron