RE: Determining File Size

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

RE: Determining File Size

Van Upboy
Subbu, thanks for the hint to look for the directoryEntry.

I have working code (see example).
When I inspect aFile then the other variables are there (for instance, there is a creationTime which contains a number, and there is a fileSize).
But the fileSize = 0.

1. What is going wrong with the fileSize, because the file is much bigger than 0!

2. How can I change creationTime to something readable? Now it is a LargePositiveInteger, not very useful to display.

| aFileDir aFile |

    aFileDir := (FileDirectory default directoryNamed: 'mytestdir').
    aFile := aFileDir directoryEntryFor: 'my test file.mp3'.
    Transcript cr;show: aFile creationTime printString.
    Transcript cr;show: aFile fileSize printString.

Regards,
Van.

Hi,

I'm listing files in a directory, but I want to show more than just the
filename (like file size and may be creation date). I've searched for some
time on the Internet, but I can't find the answer. How to do this?

I've tried this:
   aFile := (FileDirectory default directoryNamed: directoryName)
           assureExistence;
           readOnlyFileNamed: 'testfile.pdf'.
   and then tried: aFile size but that doesn't seem to work.

Regards,
Van.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/beginners/attachments/20100320/c8e4ab01/attachment-0001.htm

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

Message: 5
Date: Sat, 20 Mar 2010 21:11:59 +0530
From: "K. K. Subramaniam" <[hidden email]>
Subject: Re: [Newbies] determining file size?
To: [hidden email]
Cc: Van Upboy <[hidden email]>
Message-ID: <[hidden email]>
Content-Type: Text/Plain;  charset="iso-8859-15"

On Saturday 20 March 2010 09:02:32 pm Van Upboy wrote:
> I'm listing files in a directory, but I want to show more than just the
> filename (like file size and may be creation date). I've searched for some
> time on the Internet, but I can't find the answer. How to do this?
File size is an attribute of the file's entry in its directory.

See fileSize method in DirectoryEntry class. If you already have a file handle
or a stream opened on it, use directoryEntry method. E.g.

 stream directoryEntry fileSize

HTH .. Subbu



_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

RE: Determining File Size

K. K. Subramaniam
On Sunday 21 March 2010 01:52:46 pm Van Upboy wrote:
> Subbu, thanks for the hint to look for the directoryEntry.
>
> I have working code (see example).
> When I inspect aFile then the other variables are there (for instance,
> there is a creationTime which contains a number, and there is a fileSize).
> But the fileSize = 0.
> 1. What is going wrong with the fileSize, because the file is much bigger
> than 0!
Make sure the file exists! Try inspecting each line in the workspace to see if  
you are using the right path elements.
> 2. How can I change creationTime to something readable? Now it is a
> LargePositiveInteger, not very useful to display.
Time fromSeconds: self creationTime.
or
Date fromSeconds: self creationTime.

will convert time from epoch counts to d/m/y, h:m:s forms.

HTH .. Subbu
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners