Filesystem access

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

Filesystem access

Andrew Coppin
OK, a few questions...

1. Is there *any* way to determine how large a file is *without* opening
it? The only library function I can find to do with file sizes is
hFileSize; obviously this only works for files that you have permission
to open!

2. Is there any way to discover Windoze-style "attributes" for files?
(Read-only, archive, system, hidden, et al.)

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Filesystem access

Andrea Rossato
On Thu, Jun 21, 2007 at 09:19:51PM +0100, Andrew Coppin wrote:
>  OK, a few questions...
>
>  1. Is there *any* way to determine how large a file is *without* opening it?
>  The only library function I can find to do with file sizes is hFileSize;
>  obviously this only works for files that you have permission to open!

System.Posix.Files
fileSize


>  2. Is there any way to discover Windoze-style "attributes" for files?
>  (Read-only, archive, system, hidden, et al.)

The module before, if I understand correctlu.

all the best
andrea
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Filesystem access

Andrew Coppin
Andrea Rossato wrote:

> On Thu, Jun 21, 2007 at 09:19:51PM +0100, Andrew Coppin wrote:
>  
>>  OK, a few questions...
>>
>>  1. Is there *any* way to determine how large a file is *without* opening it?
>>  The only library function I can find to do with file sizes is hFileSize;
>>  obviously this only works for files that you have permission to open!
>>    
>
> System.Posix.Files
> fileSize
>  

Does that *work* on Windoze?

Wait, hang on a sec... No, it doesn't. The module doesn't even exist.

(I was half-expecting it might work. GHC does currently run in a Unix
emulator...)

>>  2. Is there any way to discover Windoze-style "attributes" for files?
>>  (Read-only, archive, system, hidden, et al.)
>>    
>
> The module before, if I understand correctlu.
>  

No, AFAIK the archive attribute doesn't even exist on POSIX. It's a
Windoze-specific thang.

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Filesystem access

Andrea Rossato
On Thu, Jun 21, 2007 at 09:38:49PM +0100, Andrew Coppin wrote:
>  Andrea Rossato wrote:
> > On Thu, Jun 21, 2007 at 09:19:51PM +0100, Andrew Coppin wrote:
> >>  2. Is there any way to discover Windoze-style "attributes" for files?  
> >
> > The module before, if I understand correctlu.
> >  
>
>  No, AFAIK the archive attribute doesn't even exist on POSIX. It's a
>  Windoze-specific thang.

is "Windoze-style" Windows or something that is not windows, such as
POSIX?

I did not understand correctly, but you were far from being clear.
Which is the first step to get hep, btw.

sorry for you problems. don't do windows, me.

andrea
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Filesystem access

Fraser Wilson
In reply to this post by Andrew Coppin
I don't use Haskell on Windows, but if you go to

http://www.haskell.org/ghc/docs/latest/html/libraries/index.html

you'll find a package called System.Win32.File, which has these functions:

getFileAttributes :: String -> IO FileAttributeOrFlag

getFileInformationByHandle :: HANDLE -> IO BY_HANDLE_FILE_INFORMATION

The first has all sorts of attributes in it, the second has a field for length.  Maybe these will do what you want.

cheers,
Fraser.

On 6/21/07, Andrew Coppin <[hidden email]> wrote:
Andrea Rossato wrote:

> On Thu, Jun 21, 2007 at 09:19:51PM +0100, Andrew Coppin wrote:
>
>>  OK, a few questions...
>>
>>  1. Is there *any* way to determine how large a file is *without* opening it?
>>  The only library function I can find to do with file sizes is hFileSize;
>>  obviously this only works for files that you have permission to open!
>>
>
> System.Posix.Files
> fileSize
>

Does that *work* on Windoze?

Wait, hang on a sec... No, it doesn't. The module doesn't even exist.

(I was half-expecting it might work. GHC does currently run in a Unix
emulator...)

>>  2. Is there any way to discover Windoze-style "attributes" for files?
>>  (Read-only, archive, system, hidden, et al.)
>>
>
> The module before, if I understand correctlu.
>

No, AFAIK the archive attribute doesn't even exist on POSIX. It's a
Windoze-specific thang.

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe


_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Filesystem access

Esa Ilari Vuokko
In reply to this post by Andrew Coppin
On 6/21/07, Andrew Coppin <[hidden email]> wrote:
> OK, a few questions...
>
> 1. Is there *any* way to determine how large a file is *without* opening
> it? The only library function I can find to do with file sizes is
> hFileSize; obviously this only works for files that you have permission
> to open!

I think you must open file in Windows to get the size for it, but I am not
100% sure.  (That might be the reason you see sometimes files that
are just created with size 0 even as process writes to them - file is locked.)

> 2. Is there any way to discover Windoze-style "attributes" for files?
> (Read-only, archive, system, hidden, et al.)

Fraser posted some functions to help with this.  However, those attributes are
mostly outdated unless you are workin on old Windows.  For real file rights,
more in line with traditional unix right would be file ACLs.  (There's useful
flags there, too.)  Unfortunately Security api isn't in Win32 package.

Best regards,
Esa
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Filesystem access

Bulat Ziganshin-2
In reply to this post by Andrew Coppin
Hello Andrew,

Friday, June 22, 2007, 12:19:51 AM, you wrote:
> 1. Is there *any* way to determine how large a file is *without* opening
> it? The only library function I can find to do with file sizes is
> hFileSize; obviously this only works for files that you have permission
> to open!

std library doesn't contain such function, although it is easily
modeled after getModificationTime. note that on windows this will
return only lower 32 bits of file size due to using lstat() internally

another way around this is to look at getFileAttributes implementation
and build the same wrapper around win32 getfilesize function

--
Best regards,
 Bulat                            mailto:[hidden email]

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe