Solved

Check if txt. file is in use in VBScript???

Posted on 2011-02-14
5
315 Views
Last Modified: 2012-05-11
I'm using "BarTender" (label generating software) that is referencing a .txt file on our network drive. Unique serial numbers are very important to us for tracking purposes after it leaves out factory. I have script that the BarTender label is opening the .txt file, reading the value, re-writing the new value (with the original value + the number of serial tags I want to print), saves, and then closes the .txt file. The problem I'm having is although a small window of time, if I hit print from two different work stations at the same instant, both work stations are opening the .txt file at the same time and allows duplicate printing to occur. What I'm hoping to find out is if there's a way to have the script check in the .txt file is open. If so, I want it to stop the job and return an error saying "file is use please try again". If it's not in use I'd like to to continue to run through my script of opening, reading, writing, saving and closing. Any help would be greatly appreciated. thank you!

-Mike Madsen
0
Comment
Question by:mmadsen32
  • 2
5 Comments
 
LVL 9

Accepted Solution

by:
Scottyworld earned 500 total points
ID: 34893227
Not sure if exactly what you want is possible (although an expert on here may prove me wrong!!)
A workaround would be when you open the file (eg: file1.txt) for editing the first thing your script could do would be to rename it to eg:file2.txt, make any changes, then rename it back to file1.txt when finished.
That way, if you run the same script on another workstation it will not be able to find the file (file1.txt) if it is in use
0
 

Author Comment

by:mmadsen32
ID: 34896584
Thanks Scott! I'll try it out and see if that fixes the problem. It seems like it should
0
 
LVL 9

Expert Comment

by:Scottyworld
ID: 35152028
Hi,
how did you get on? Did this help with the problem?
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 35465148
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This is an explanation of a simple data model to help parse a JSON feed

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question