Solved

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

Posted on 2014-10-29
7
156 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Let’s list some of the technologies that enable smooth teleworking. 
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
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…

708 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

18 Experts available now in Live!

Get 1:1 Help Now