faqts : Computers : Programming : Languages : Tse : Block

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

Entry

TSE: Block: Save: File: Size: How to get the filesize of a block saved on disk?

Nov 12th, 2006 08:00
Knud van Eeden,


----------------------------------------------------------------------
--- Knud van Eeden --- 12 November 2006 - 04:54 pm -------------------

TSE: Block: Save: File: Size: How to get the filesize of a block saved 
on disk?

---

Method: Copying the block to a temporary buffer, saving it to disk, 
and getting the filesize of that diskfile

--- cut here: begin --------------------------------------------------

FORWARD INTEGER PROC FNBlockGetFileSizeTotalBufferSimpleI()
FORWARD INTEGER PROC FNFileGetSizeDiskDosSimpleI( STRING s1 )
FORWARD INTEGER PROC FNFileGetSizeDiskSimpleI( STRING s1 )
FORWARD INTEGER PROC FNFileGetSizeDiskWindowsSimpleI( STRING s1 )
FORWARD PROC Main()


// --- MAIN --- //

PROC Main()

 Message( FNBlockGetFileSizeTotalBufferSimpleI() ) // gives e.g. 410 
bytes filesize totally in the currently marked block

END

// --- LIBRARY --- //

// library: block: get: character: total: simple 
(filenamemacro=getbltsi.s) [kn, ri, su, 12-11-2006 15:21:47]

INTEGER PROC FNBlockGetFileSizeTotalBufferSimpleI()
 INTEGER I = 0
 INTEGER bufferI = 0
 STRING fileNameS[255] = ""
 IF NOT IsBlockMarked()
  Warn( "Please mark a block" )
  RETURN( 0 )
 ENDIF
 PushPosition()
 PushBlock()
 Copy()
 bufferI = CreateTempBuffer()
 IF ( bufferI == 0 )
  Warn( "could not create a temporary buffer" )
  RETURN( 0 )
 ENDIF
 IF GotoBufferId( bufferI )
  Paste()
  fileNameS = MakeTempName( "." )
  SaveBlock( fileNameS )
  I = FNFileGetSizeDiskSimpleI( fileNameS )
  IF NOT EraseDiskFile( fileNameS )
   Warn( Format( "could not erase", fileNameS, " ", "on disk" ) )
  ENDIF
  AbandonFile( bufferI )
 ELSE
  Warn( "could not goto the temporary buffer" )
  RETURN( 0 )
 ENDIF
 //
 PopPosition()
 PopBlock()
 RETURN( I )
END

// library: file: size: disk: return the total amount of bytes the 
file takes on disk (filenamemacro=getfidsi.s) [kn, ri, tu, 02-01-2001 
03:32:03]

INTEGER PROC FNFileGetSizeDiskSimpleI( STRING filenameS )
 #IFDEF WIN32
  RETURN( FNFileGetSizeDiskWindowsSimpleI( filenameS ) )
 #ELSE
  RETURN( FNFileGetSizeDiskDosSimpleI( filenameS ) )
 #ENDIF
END

// library: file: get: size: disk: windows: return the total amount of 
bytes the file takes on disk / TSE for Windows only 
(filenamemacro=getfiwsi.s) [kn, ri, we, 29-08-2001 01:59:13]

INTEGER PROC FNFileGetSizeDiskWindowsSimpleI( STRING filenameS )
 #IFDEF WIN32
  INTEGER filesizeI = 0
  IF FindThisFile( filenameS, _HIDDEN_ | _SYSTEM_ | _READONLY_ )
   filesizeI = FFSize()
  ELSE

   Warn( Format( filenameS, "not found (thus filesize in bytes could 
not be determined)" ) )

   filesizeI = 0
  ENDIF
  RETURN( filesizeI )
 #ELSE
  // do nothing
 #ENDIF
END

// library: file: size: disk: return the total amount of bytes the 
file takes on disk / TSE for DOS only [kn, ri, tu, 02-01-2001 03:32:03]

INTEGER PROC FNFileGetSizeDiskDosSimpleI( STRING filenameS )

 #IFDEF WIN32
  // do nothing
 #ELSE
  STRING dtaS[80] = ""
  STRING s[50] = ""
  SetDTA( dtaS )
  IF NOT FindFirst( filenameS, _READONLY_ | _HIDDEN_ | _SYSTEM_ )
   Warn( Format( filenameS, " ", "not found" ) )
   RETURN( 0 )
  ENDIF
  s = DecodeDTA( dtaS )
  RETURN( Val( Trim( s[16:9] ) ) )
 #ENDIF
END

--- cut here: end ----------------------------------------------------

===

Internet: see also:

---



----------------------------------------------------------------------