Solved

Quickest AUTOMATED way (in FOXPRO) to determine if ANY files in given Folder are in use

Posted on 2014-10-29
7
160 Views
Last Modified: 2014-11-03
The quickest manual way to determine if any files in a given folder are in use is to try to rename the folder. If you can, then no files are in use, if you can't then something is using one or more of the files.

How would we automate that in vfp9?

So far I've created a simple batch file which returns an exit code thus:

e:
cd\
if exist 00test goto renfold
exit /B 1
:renfold
rename 00test 000test
if exist 000test goto success
exit /B 1
:success
exit /B 0

which returns an exit code of 1 for failure (either because the initial folder didn't exist or the rename failed) and 0 if the rename works.

but although I can run that from vfp (using RUN [BATCHFILE.BAT]) I can't seem to capture the exit code within the vfp environment.  (It would be even nicer if we could pass parameters to the batchfile to specify the source and target names but I can live with hard coded names.)
0
Comment
Question by:mjacobs2929
  • 4
  • 3
7 Comments
 
LVL 2

Expert Comment

by:GEOFS
ID: 40415913
You could create a small file if the rename is successful, then check for its existence in the VFP program after the RUN is executed.

Also, batch files can receive command line parameters.  As I recall, they're identified by tags like %1, %2, etc.
0
 
LVL 2

Expert Comment

by:GEOFS
ID: 40415990
You could also just test for the existence of the new folder after the RUN has finished.
0
 

Author Comment

by:mjacobs2929
ID: 40416314
"Also, batch files can receive command line parameters.  As I recall, they're identified by tags like %1, %2, etc."

looks interesting. Can you provide a line or two of code to illustrate?

"You could create a small file if the rename is successful, then check for its existence in the VFP program after the RUN is executed."

woudn't test the same thing. All that tests is whether you have write access to the folder. That aint the issue.

The issue is one or more users using one or more tables in the target folder (or one of its subfolders) Changing the name of the folder is a good test for that because if any file is open on a remote workstation, windoze won't allow the folder to be renamed.

Same objection applies to the "Create folder" suggestion.

But if you can show me the code for capturing the batch file exit codes, we're home and dry...
0
New My Cloud Pro Series - organize everything!

With space to keep virtually everything, the My Cloud Pro Series offers your team the network storage to edit, save and share production files from anywhere with an internet connection. Compatible with both Mac and PC, you're able to protect your content regardless of OS.

 
LVL 2

Expert Comment

by:GEOFS
ID: 40416364
To parameterize the batch file, change the RENAME command to "RENAME %1 %2", then call the batch file with the before and after names of the folder.

Creating a file would indeed require write access to the folder, but wouldn't you also need that to change its name?

My suggestion was to test for the existence of the renamed folder, not to create a folder.  One way to do that is to call ADIR() and see if it returns a value greater than 0.
0
 

Author Comment

by:mjacobs2929
ID: 40417202
You appear to be implying something like


LOCAL EXITCODE,SOURCENAME,TARGETNAME

SOURCENAME=(CURRENT FOLDERNAME)
TARGETNAME=SOURCENAME+'.1' &&small arbitrary change for test only

RUN RENAME.BAT WITH SOURCENAME,TARGETNAME TO EXITCODE

IF EXITCODE=(etc)

I've already tried something like that (without parameters) but nothing gets passed to "EXITCODE"

If you have the form of coding which solves THAT problem, it's exactly what I'm after
0
 
LVL 2

Accepted Solution

by:
GEOFS earned 500 total points
ID: 40417494
I don't know of a way to pass the batch file's exit code back to the calling VFP program.  That's why I suggested testing for the existence of the target folder after the batch file finishes.  Here's a simple example of how you might change the name of folder 'XXX' in the root of C: to 'YYY'.  The use of ADIR() assumes that there's at least one file in the folder.


Sample batch file code:
C:
CD \
RENAME %1 %2


Sample VFP code:

SET DEFAULT TO C:
CHDIR \
cOldFolder = "XXX"
cNewFolder = "YYY"
cRunCmd = "TEST " + cOldFolder + " " + cNewFolder
RUN &cRunCmd
IF  ADIR(aList,cNewFolder+"\*") > 0
   <The folder name has been changed>
ENDIF
0
 

Author Comment

by:mjacobs2929
ID: 40419121
ah, I've finally twigged your approach. I couldn't see how what you were saying could capture the exit code but now I realise you weren't trying to do that. Your approach is simply to test whether or not the rename took place. I accept that is an alternative and it would work, though I think it could be done even more simply than you suggest

RUN RENAME.BAT (or whatever)
if directory(newname)
 etc

The exit code capture is really my main aim as there are dozens of similar examples where it would be very useful to be able to do that. However I'll close the question and give you the points. I'll resurrect the exit code question when I have a more pressing example of its usefulness.

Cheers
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

If your business is like most, chances are you still need to maintain a fax infrastructure for your staff. It’s hard to believe that a communication technology that was thriving in the mid-80s could still be an essential part of your team’s modern I…
If you're not part of the solution, you're part of the problem.   Tips on how to secure IoT devices, even the dumbest ones, so they can't be used as part of a DDoS botnet.  Use PRTG Network Monitor as one of the building blocks, to detect unusual…
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

863 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now