DIRECTORY() Function not giving fresh information?

DIRECTORY() Function not giving fresh information?

Postby Ollie » Thu Apr 12, 2012 10:39 am

Hi guys,

My application launches a 3rd party program (in a hidden window) that downloads some files into a folder.
I want my application to report back on the progress. I am running a TIMER that calls the function below to get the folder size every 1000ms and displays it.

Its returned value doesn't change - its as if its cached or something. If I go into the folder with windows, refresh its contents - F5 - my application's folder size is updated. But if I don't do that - it just sits there with the "old" information.

How can I get it to give me the most up-to-date size every second?

Code: Select all  Expand view
STATIC FUNCTION GetFolderSize(cPath)
   //Returns the total filesize of a folder cPath
   LOCAL adir, nfoldersize,i
   aDir = DIRECTORY( cPath + "\*.*", "D" )
   nFolderSize = 0
    FOR i = 1 TO LEN( aDir )
       nFolderSize += aDir[ i, 2 ]
       //1 = Filename
       //2 = Filesize
    NEXT
    //? "Folder Size: "+STR(nFolderSize)
    RETURN (nFolderSize)
 
Many thanks
Ollie.

Using:
xHarbour Compiler build 1.2.1 (SimpLex) (Rev. 6406)
Borland C++ 5.5.1
FWH 9.04 (2009 Apr)
Ollie
 
Posts: 233
Joined: Sat Dec 30, 2006 6:10 am

Re: DIRECTORY() Function not giving fresh information?

Postby ukoenig » Fri Apr 13, 2012 9:34 pm

Ollie,

with my new Tool You can get it working :
You can watch, changing the contents of the subfolder \images, how the size changes.
Changing ( delete / add files ) inside the File-browser, shows the result inside the Timer.
I changed the original field < Year > against < Dir-size >.

Download ( Exe, Prg and Images ) :
http://www.pflegeplus.com/fw_download/testsize.zip

1. getting the size of all files :

Image

2. deleting a file, returns a new size :

Image

The Timer-part :

Code: Select all  Expand view

FUNCTION SHOW_TD()
LOCAL oTDTitle, oTime, oDate1, oDate2, oDate3, oDate4
LOCAL cTime := Time()
LOCAL cDate1 := ALLTRIM( STR( YEAR( DATE() ) ) )
LOCAL cDate2 := CMONTH( Date() )
LOCAL cDate3 := CDOW( Date() )
LOCAL cDate4 := ALLTRIM( STR( DAY(DATE()) ))

@  50, 50 TITLE oTDTitle SIZE 350, 99 OF oWnd TRANSPARENT SHADOWSIZE 0

oTDTitle:lRound := .T.
oTDTitle:lBorder := .T.

// Shadow Tansparent-intensity ( 10 = Low / 70 = Black )
oTDTitle:nShadowIntensity = 20

// Animated Title-Image
// ----------------------------
@  10, 10 TITLEIMG OF oTDTitle BITMAP c_path + "\Images\Clock.bmp" TRANSPARENT ;
ANIMA LEVEL 255 ;
ACTION MsgAlert( "Button with Action","Attention" )
// Time
@ 10, 68 TITLETEXT oTime OF oTDTitle TEXT cTime  FONT oTimeFont ;
SHADOW BOTTOMRIGHT COLOR 65535
// Day
@ 47, 68  TITLETEXT oDate1 OF oTDTitle TEXT cDate1  FONT oTimeFont ;
SHADOW BOTTOMRIGHT COLOR 255
// Month
@ 47, 125 TITLETEXT oDate2 OF oTDTitle TEXT cDate2  FONT oDateFont ;
SHADOW BOTTOMRIGHT COLOR 65535
// Weekday
@ 66, 125 TITLETEXT oDate3 OF oTDTitle TEXT cDate3  FONT oDateFont ;
SHADOW BOTTOMRIGHT COLOR 65535
// Year
@ 47, 150.0 TITLETEXT oDate4 OF oTDTitle TEXT cDate4  FONT oTimeFont ;
SHADOW BOTTOMRIGHT COLOR 255
// Text Shadow-Color
// -------------------------
oTDTitle:nShadowTxtClr := 10461087
// Text-Shadow-Distance
 // ------------------------------
oTDTitle:nShadowTxtDis := 1

DEFINE TIMER oTimer INTERVAL 500 ;
ACTION GETDATA2( oTime, oDate1, oDate2, oDate3, oDate4 ) OF oWnd
ACTIVATE TIMER oTimer

RETURN ( NIL )

// ------ YEAR replaced, using Your directory-function !!!! ---------

FUNCTION GETDATA2( oTime, oDate1, oDate2, oDate3, oDate4 )
LOCAL oTime1 := TTime():System(), adir, nfoldersize, i

cTime := oTime1:cGetTime()

cDate1 := ALLTRIM( STR( DAY(DATE()) )) 
cDate2 := CMONTH( Date() )
cDate3 := CDOW( Date() )
// cDate4 := ALLTRIM( STR( YEAR( DATE() ) ) )

oTime:SetText( cTime )

oDate1:SetText( cDate1 )
oDate2:SetText( cDate2 )
oDate3:SetText( cDate3 )
// oDate4:SetText( cDate4 ) REPLACED !!!!

aDir = DIRECTORY(c_path + "\Images\*.*", "D" )
nFolderSize = 0
FOR i = 1 TO LEN( aDir )
       nFolderSize += aDir[ i, 2 ]
       //1 = Filename
       //2 = Filesize
NEXT
oDate4:SetText( STR(nFolderSize) )

RETURN NIL
 


Best Regards
Uwe :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: DIRECTORY() Function not giving fresh information?

Postby Ollie » Sun Apr 15, 2012 6:10 am

Hey Uwe- Thanks for that!

It seems your app behaves the same as mine though. Your app watches the size of the ../images folder - so I made my app download to that folder and had your app (and mine) watch the folder size while I download file from the internet into it.

Both our apps behave as follows: it updates the size correctly for about 5 updates - then our apps show the same size even while the download is continuing and the folder size is growing. If I make windows refresh the folder - (select all files, right click - properties) - our apps update with the correct size. But again, they don't update every second - they just report the same folder size- even though the folder is growing.

Its as if windows doesn't want to give fresh information requested by directory() continually.

I can upload the app here if you would like to do the same test I did above.

Ollie.
Many thanks
Ollie.

Using:
xHarbour Compiler build 1.2.1 (SimpLex) (Rev. 6406)
Borland C++ 5.5.1
FWH 9.04 (2009 Apr)
Ollie
 
Posts: 233
Joined: Sat Dec 30, 2006 6:10 am

Re: DIRECTORY() Function not giving fresh information?

Postby ukoenig » Sun Apr 15, 2012 9:46 am

Hello Ollie,

I agree with You,
I opend both the viewer and filemanager next each other,
with the filemanager I selected about 20 files and inserted them to the \image - directory.
Only a few countings are shown, than it stopped.
Because of same results, It gives me the basics, to look for another solution.

I tested to copy file by file with no problem.
Maybe the timer-intervall must be changed.
Also I will try to copy 10 big files at once with the filemanager, to see what happens.

Best regards
Uwe :cry:
Last edited by ukoenig on Sun Apr 15, 2012 10:01 am, edited 1 time in total.
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: DIRECTORY() Function not giving fresh information?

Postby Ollie » Sun Apr 15, 2012 9:55 am

Thank you.
Many thanks
Ollie.

Using:
xHarbour Compiler build 1.2.1 (SimpLex) (Rev. 6406)
Borland C++ 5.5.1
FWH 9.04 (2009 Apr)
Ollie
 
Posts: 233
Joined: Sat Dec 30, 2006 6:10 am

Re: DIRECTORY() Function not giving fresh information?

Postby ukoenig » Sun Apr 15, 2012 11:12 am

Ollie,

some more test, I found the reason.
It is the timer-interval.
The needed timer-interval belongs to the file-size.

I copied 80 small BMP-files and used :
DEFINE TIMER oTimer INTERVAL 100
The result was OK.


I changed :
DEFINE TIMER oTimer INTERVAL 500
to :
DEFINE TIMER oTimer INTERVAL 2000
using bigger files

The result of 13 files with 604 MB was OK.
It means, You need the average file-size, to adjust the timer-interval.
Maybe some tests needed.

Image

Image

Best Regards
Uwe :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: DIRECTORY() Function not giving fresh information?

Postby ukoenig » Sun Apr 15, 2012 2:52 pm

Ollie,

a much better extended test.

Now it is possible, to change the Timer-interval at runtime.
A subdirectory /Files is included to test the directory-size.
The display is counting the files.
You can change the Timer-interval at runtime.
I hope it works for You.

Download :
http://www.pflegeplus.com/fw_downloads/timer1.zip

With the highest Value, the timer slows down and only refreshes every 2. second

Image

Best Regards
Uwe :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot], nageswaragunupudi and 138 guests