• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 173
  • Last Modified:

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.)
0
mjacobs2929
Asked:
mjacobs2929
  • 4
  • 3
1 Solution
 
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.
0
 
GEOFSCommented:
You could also just test for the existence of the new folder after the RUN has finished.
0
 
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...
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
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.
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
0
 
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
0
 
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
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now