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

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.)
mjacobs2929Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GEOFSCommented:
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.
GEOFSCommented:
You could also just test for the existence of the new folder after the RUN has finished.
mjacobs2929Author Commented:
"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...
SolarWinds® IP Control Bundle (IPCB)

Combines SolarWinds IP Address Manager and User Device Tracker to help detect IP conflicts, quickly identify affected systems, and help your team take near instantaneous action. Help improve visibility and enhance reliability with SolarWinds IP Control Bundle.

GEOFSCommented:
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.
mjacobs2929Author Commented:
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
GEOFSCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mjacobs2929Author Commented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Utilities

From novice to tech pro — start learning today.