  DFWDraco76 Premium join:2001-02-21 Plano, TX clubs:
·Verizon FIOS
| VBScript - test if text file is in use
I'm working on something where there is a chance a text file I need to open/modify in vbscript might already be in use... so I'm trying to figure out a way to test if that's the case.
this does not seem to work for text files...
Any other ideas? I could test the LastModified property, but if the file was just opened would that reflect anything? (i.e. it only updates when the file is saved, right?)
I tried the "openfiles" command but again, it doesn't reflect anything about text files. (note the given url is for xp, but the parameters are much more limited on server 2k3) -- »blog.thelifeofbrian.info |
|
  PapaDos Cum Grano Salis Premium,MVM join:2001-02-08 Lasalle, QC | There is nothing special about "text files", they are just files. The problem might be your definition of "in use" ? -- Festina Lente |
|
  cowboyro
join:2000-10-11 Shelton, CT | reply to DFWDraco76 I assume "in use" means open for write. Easiest would be to try to open it for write and catch the error if any. |
|
  PToN
join:2001-10-04 Houston, TX
| said by cowboyro :I assume "in use" means open for write. Easiest would be to try to open it for write and catch the error if any. It depends. Since you can open a file with notepad multiple times without getting an error.. So Your method doesnt apply for every scenario. |
|
  PetePuma How many lumps do you want Premium,MVM join:2002-06-13 Arlington, VA | reply to DFWDraco76 What happens if you try calling OpenTextFile with "forWriting" and the create flag = false?
"In use" is kind of squishy. It depends on how the file was opened by the other user/application as to whether or not the OS will let you open it. |
|
  DFWDraco76 Premium join:2001-02-21 Plano, TX clubs:
·Verizon FIOS
| reply to DFWDraco76 Thanks for the responses! Unfortunately other fires came up today and I haven't even had time (since posting) to think about this.
I'll follow up when I'm able to get back around to it... -- »blog.thelifeofbrian.info |
|
  cowboyro
join:2000-10-11 Shelton, CT | reply to PToN Open pathname For mode [Access access] [lock] As [#]filenumber [Len=reclength] You can always open the file with a lock  |
|
  DFWDraco76 Premium join:2001-02-21 Plano, TX clubs:
·Verizon FIOS
| said by cowboyro :Open pathname For mode [Access access] [lock] As [#]filenumber [Len=reclength] You can always open the file with a lock Sorry I don't understand - can you explain how to lock the file more clearly? You're talking about vbscript, right? -- »blog.thelifeofbrian.info |
|
  DFWDraco76 Premium join:2001-02-21 Plano, TX clubs:
·Verizon FIOS
| just getting back to this....
came up with a simple kludge/workaround: * when a change needs to be made to the file, copy filename.txt to filename.txt.inuse and delete filename.txt * make whatever changes are necessary * when done, copy filename.txt.inuse back to filename.txt and delete the .inuse version
For the "clients" needing to modify the file: * check for existence of the .inuse file; if it's there, sleep x seconds, else follow the algorithm above.
I think that will work for us... -- »blog.thelifeofbrian.info |
|