Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File Size & Date

Status
Not open for further replies.

Shanachie

Programmer
Jun 18, 2000
92
US
I have a need to check the file size and date of some files to compare for updating. (If the file is not the same as the one on the server, update it.) How do I do that in VFP?

TIA, as usual!
Shanachie
 
Check out aDir() in VFP help.


Don


 
FUNCTION GetFileSize
PARAMETERS gcFileName && File to be checked
PRIVATE pnHandle,pnSize
IF PARAMETERS( ) = 0
RETURN -2 && Return -2 if no parameter passed
ELSE
IF !FILE(gcFileName)
RETURN -1 && Return -1 if file does not exist
ENDIF
ENDIF
pnHandle = FOPEN(gcFileName) && Open file
pnSize = FSEEK(pnHandle,0,2) && Determine file size, assign to pnSize
=FCLOSE(pnHandle) && Close file
RETURN pnSize && Return value


Ali Koumaiha
TeknoSoft Inc
Farmington Hills, Michigan
 
For file date, check out FDATE()

? Fdate("C:\SomeFile.DAT") && 01/01/2003

Ali Koumaiha
TeknoSoft Inc
Farmington Hills, Michigan
 
Hi SHanachie

For updtae purposes, file size shall not be the crieteria. It is because, when you just do an update of one record, without a deletion, the size could remain same. (It may not always remain same, depending on block factors, just as in FPT files, but it can remain same.)

SO I would check for the DATE of last update.
*********************************************
sFiles = ADIR(laSource,"mySource\*.DBF")
bFiles = ADIR(laBack,"myBackPath\*.DBF")

FOR I = 1 TO sFiles
WAIT WINDOW "File Copying in Progress..."+laSource(i,1);
NOWAIT NOCLEAR
lFound = .f.
FOR x = 1 TO bFiles
IF UPPER(laBack(x,1)) == UPPER(laSource(i,1))
** Date copmparison
IF laBack(x,3) = laSource(i,3)
** Not new
lFound = .t.
EXIT
ELSE
** DO a file copy using .*
** to cover .DBF/.CDX/.FPT etc.
lFound = .t.
ENDIF
ENDIF
ENDFOR
IF ! lFound
** File is a new file - not in backup at all.
** DO a file copy using .*
** to cover .DBF/.CDX/.FPT etc.
ENDIF
ENDFOR
WAIT CLEAR
****************************************
I have just coded here and so not checked for errors.
Use with caution and check results.
:)

ramani :)
(Subramanian.G)
 
A WSH solution:
Code:
*The First LOCAL is only valid in 7.0 & 8.0 and NOT required

LOCAL oFS as 'Scripting.FileSystemObject'
LOCAL lcfilename
lcFileName ='c:\autoexec.bat'

oFS=CreateObject('Scripting.FileSystemObject')

With oFS
   If .FileExists(lcFileName)
	? .GetFile(lcFileName).DateCreated
	? .Getfile(lcFileName).DateLastAccessed
	? .Getfile(lcFileName).DateLastModified
	? .Getfile(lcFileName).Size
   Endif
Endwith
Release oFS
Rick
 
Thanks, all!

Right you are! The files I'm checking out are .EXE's (the latest version of the application, with a copy given the name "MyApp Current.EXE"), so the size is irrelevent, as pointed out above. The critical thing is the date/time. FDATE(), with the argument to return DateTime, does the trick nicely. The code is wrapped in a short "primer" program that checks the file dates, updates it if necessary, and then runs the application.

I could have implemented this through a shortcut to the server file but copying it to the users' desktops keeps network traffic down. (The app is 1.2MB.)

Thanks Again!

Shanachie
 
HI Shanachie,

Why don't you use the Version of the exe to determine if an update is needed or not?

DIMENSION aVer[1],nVer[1]
AGETFILEVERSION(aVer,'YourApp.exe')
AGETFILEVERSION(aVer,'UpdatedApp.exe')
? aVer[4] && YourApp Version
? nVer[4] && Updated App version.



Ali Koumaiha
TeknoSoft Inc
Farmington Hills, Michigan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top