Problem with FileSystem in WIndows

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

Problem with FileSystem in WIndows

CdAB63

Good night all.

 

I´ve had trouble in windows concerning FileSystem.

 

((FileSystem disk root) / ‘C:\temp\e8720bb4-b90a-0d00-9b1f-008709e5552b.txt’) delete

 

Fails as if the file didn´t exist. Message:

 

FileDoesNotExist: Path / ‘C:\temp\e8720bb4-b90a-0d00-9b1f-008709e5552b.txt’

 

And I wonder what´s wrong. Because it works in linux and MacOS.

 

Trasncript show: ((FileSYstem disk root) / ‘C:\temp\e8720bb4-b90a-0d00-9b1f-008709e5552b.txt’)

 

Returns:

 

File @ C:\temp\e8720bb4-b90a-0d00-9b1f-008709e5552b.txt\

 

And I wonder where the last \ came from and if is it that is messing all and how to fix things.

 

Best regards,

 

Casimiro Barreto


Livre de vírus. www.avast.com.
Reply | Threaded
Open this post in threaded view
|

Re: Problem with FileSystem in WIndows

Max Leske
Hi Casimiro,

have you tried using normal slashes in the path name? FileSystem should convert those to system path delimiters automatically. So:

C:/temp/e8720bb4-b90a-0d00-9b1f-008709e5552b.txt

And possibly you'll need a leading slash, as "C:" is a reference to the root of the file system:

/C:/temp/e8720bb4-b90a-0d00-9b1f-008709e5552b.txt

Cheers,
Max

On 30 Apr 2017, at 03:15, Casimiro de Almeida Barreto <[hidden email]> wrote:

Good night all.
 
I´ve had trouble in windows concerning FileSystem.
 
((FileSystem disk root) / ‘C:\temp\e8720bb4-b90a-0d00-9b1f-008709e5552b.txt’) delete
 
Fails as if the file didn´t exist. Message:
 
FileDoesNotExist: Path / ‘C:\temp\e8720bb4-b90a-0d00-9b1f-008709e5552b.txt’
 
And I wonder what´s wrong. Because it works in linux and MacOS.
 
Trasncript show: ((FileSYstem disk root) / ‘C:\temp\e8720bb4-b90a-0d00-9b1f-008709e5552b.txt’)
 
Returns:
 
File @ C:\temp\e8720bb4-b90a-0d00-9b1f-008709e5552b.txt\
 
And I wonder where the last \ came from and if is it that is messing all and how to fix things.
 
Best regards,
 
Casimiro Barreto

Livre de vírus. www.avast.com. 

Reply | Threaded
Open this post in threaded view
|

Re: Problem with FileSystem in WIndows

Sven Van Caekenberghe-2

> On 30 Apr 2017, at 09:48, Max Leske <[hidden email]> wrote:
>
> Hi Casimiro,
>
> have you tried using normal slashes in the path name? FileSystem should convert those to system path delimiters automatically. So:
>
> C:/temp/e8720bb4-b90a-0d00-9b1f-008709e5552b.txt
>
> And possibly you'll need a leading slash, as "C:" is a reference to the root of the file system:
>
> /C:/temp/e8720bb4-b90a-0d00-9b1f-008709e5552b.txt

There is also the following option:

        FileLocator C / 'temp' / 'e8720bb4-b90a-0d00-9b1f-008709e5552b.txt'

> Cheers,
> Max
>
>> On 30 Apr 2017, at 03:15, Casimiro de Almeida Barreto <[hidden email]> wrote:
>>
>> Good night all.
>>  
>> I´ve had trouble in windows concerning FileSystem.
>>  
>> ((FileSystem disk root) / ‘C:\temp\e8720bb4-b90a-0d00-9b1f-008709e5552b.txt’) delete
>>  
>> Fails as if the file didn´t exist. Message:
>>  
>> FileDoesNotExist: Path / ‘C:\temp\e8720bb4-b90a-0d00-9b1f-008709e5552b.txt’
>>  
>> And I wonder what´s wrong. Because it works in linux and MacOS.
>>  
>> Trasncript show: ((FileSYstem disk root) / ‘C:\temp\e8720bb4-b90a-0d00-9b1f-008709e5552b.txt’)
>>  
>> Returns:
>>  
>> File @ C:\temp\e8720bb4-b90a-0d00-9b1f-008709e5552b.txt\
>>  
>> And I wonder where the last \ came from and if is it that is messing all and how to fix things.
>>  
>> Best regards,
>>  
>> Casimiro Barreto
>>
>> Livre de vírus. www.avast.com.
>


Reply | Threaded
Open this post in threaded view
|

RES: Problem with FileSystem in WIndows

CdAB63
Hello,

-----Mensagem original-----
De: Pharo-dev [mailto:[hidden email]] Em nome de Sven Van Caekenberghe
Enviada em: domingo, 30 de abril de 2017 05:30
Para: Pharo Development List <[hidden email]>
Assunto: Re: [Pharo-dev] Problem with FileSystem in WIndows


> On 30 Apr 2017, at 09:48, Max Leske <[hidden email]> wrote:
>
> Hi Casimiro,
>
> have you tried using normal slashes in the path name? FileSystem should convert those to system path delimiters automatically. So:

It seems that FileSystem does not convert / into \ .
((FileSystem root) / 'c:\temp\tempfile.txt')  writeStream won´t work but...
FileStream fileNamed: 'C:\temp\tempfile.txt' works ok.

So... I could make it work for getting a stream both for Unix and Windows:

        OSPlatform currentPlatformName = 'unix'
        ifTrue: [
                [ str := (fs / fn) writeStream ] on: Exception do: [ ^ nil ] ]
        ifFalse: [
                [ str := FileStream fileNamed: fn ] on: Exception do: [ ^ nil ] ].

And to delete:

        OSPlatform currentPlatformName = 'unix'
        ifTrue: [
                (FileSystem root / aFileName) delete ]
        ifFalse: [
                rgx := RxMatcher forString: '^[A-Z]\:'.
                drive := rgx matchesIn: aFileName.
                drive := (drive at: 1) copyWithRegex: '\:' matchesReplacedWith: ''.
                ((FileLocator driveNamed: drive)  / (aFileName copyWithRegex: '^[A-Z]\:' matchesReplacedWith: '')) delete ]

Not good, nor elegant nor anything close to good transparent code but... works :'(

>
> C:/temp/e8720bb4-b90a-0d00-9b1f-008709e5552b.txt
>
> And possibly you'll need a leading slash, as "C:" is a reference to the root of the file system:
>
> /C:/temp/e8720bb4-b90a-0d00-9b1f-008709e5552b.txt

There is also the following option:

        FileLocator C / 'temp' / 'e8720bb4-b90a-0d00-9b1f-008709e5552b.txt'

> Cheers,
> Max
>
>> On 30 Apr 2017, at 03:15, Casimiro de Almeida Barreto <[hidden email]> wrote:
>>
>> Good night all.
>>
>> I´ve had trouble in windows concerning FileSystem.
>>
>> ((FileSystem disk root) / ‘C:\temp\e8720bb4-b90a-0d00-9b1f-008709e5552b.txt’) delete
>>
>> Fails as if the file didn´t exist. Message:
>>
>> FileDoesNotExist: Path / ‘C:\temp\e8720bb4-b90a-0d00-9b1f-008709e5552b.txt’
>>
>> And I wonder what´s wrong. Because it works in linux and MacOS.
>>
>> Trasncript show: ((FileSYstem disk root) / ‘C:\temp\e8720bb4-b90a-0d00-9b1f-008709e5552b.txt’)
>>
>> Returns:
>>
>> File @ C:\temp\e8720bb4-b90a-0d00-9b1f-008709e5552b.txt\
>>
>> And I wonder where the last \ came from and if is it that is messing all and how to fix things.
>>
>> Best regards,
>>
>> Casimiro Barreto
>>
>> Livre de vírus. www.avast.com.
>




---
Este email foi escaneado pelo Avast antivírus.
https://www.avast.com/antivirus


Reply | Threaded
Open this post in threaded view
|

Re: RES: Problem with FileSystem in WIndows

Stephane Ducasse-3
Can you open a bug entry with clear examples?
We should improve this part. 
After having the interpretation of strings sucks. I do not like it I prefer

FileLocator C / 'temp' / 'e8720bb4-b90a-0d00-9b1f-008709e5552b.txt'

On Sun, Apr 30, 2017 at 6:54 PM, Casimiro de Almeida Barreto <[hidden email]> wrote:
Hello,

-----Mensagem original-----
De: Pharo-dev [mailto:[hidden email]] Em nome de Sven Van Caekenberghe
Enviada em: domingo, 30 de abril de 2017 05:30
Para: Pharo Development List <[hidden email]>
Assunto: Re: [Pharo-dev] Problem with FileSystem in WIndows


> On 30 Apr 2017, at 09:48, Max Leske <[hidden email]> wrote:
>
> Hi Casimiro,
>
> have you tried using normal slashes in the path name? FileSystem should convert those to system path delimiters automatically. So:

It seems that FileSystem does not convert / into \ .
((FileSystem root) / 'c:\temp\tempfile.txt')  writeStream won´t work but...
FileStream fileNamed: 'C:\temp\tempfile.txt' works ok.

So... I could make it work for getting a stream both for Unix and Windows:

        OSPlatform currentPlatformName = 'unix'
        ifTrue: [
                [ str := (fs / fn) writeStream ] on: Exception do: [ ^ nil ] ]
        ifFalse: [
                [ str := FileStream fileNamed: fn ] on: Exception do: [ ^ nil ] ].

And to delete:

        OSPlatform currentPlatformName = 'unix'
        ifTrue: [
                (FileSystem root / aFileName) delete ]
        ifFalse: [
                rgx := RxMatcher forString: '^[A-Z]\:'.
                drive := rgx matchesIn: aFileName.
                drive := (drive at: 1) copyWithRegex: '\:' matchesReplacedWith: ''.
                ((FileLocator driveNamed: drive)  / (aFileName copyWithRegex: '^[A-Z]\:' matchesReplacedWith: '')) delete ]

Not good, nor elegant nor anything close to good transparent code but... works :'(

>
> C:/temp/e8720bb4-b90a-0d00-9b1f-008709e5552b.txt
>
> And possibly you'll need a leading slash, as "C:" is a reference to the root of the file system:
>
> /C:/temp/e8720bb4-b90a-0d00-9b1f-008709e5552b.txt

There is also the following option:

        FileLocator C / 'temp' / 'e8720bb4-b90a-0d00-9b1f-008709e5552b.txt'

> Cheers,
> Max
>
>> On 30 Apr 2017, at 03:15, Casimiro de Almeida Barreto <[hidden email]> wrote:
>>
>> Good night all.
>>
>> I´ve had trouble in windows concerning FileSystem.
>>
>> ((FileSystem disk root) / ‘C:\temp\e8720bb4-b90a-0d00-9b1f-008709e5552b.txt’) delete
>>
>> Fails as if the file didn´t exist. Message:
>>
>> FileDoesNotExist: Path / ‘C:\temp\e8720bb4-b90a-0d00-9b1f-008709e5552b.txt’
>>
>> And I wonder what´s wrong. Because it works in linux and MacOS.
>>
>> Trasncript show: ((FileSYstem disk root) / ‘C:\temp\e8720bb4-b90a-0d00-9b1f-008709e5552b.txt’)
>>
>> Returns:
>>
>> File @ C:\temp\e8720bb4-b90a-0d00-9b1f-008709e5552b.txt\
>>
>> And I wonder where the last \ came from and if is it that is messing all and how to fix things.
>>
>> Best regards,
>>
>> Casimiro Barreto
>>
>>      Livre de vírus. www.avast.com.
>




---
Este email foi escaneado pelo Avast antivírus.
https://www.avast.com/antivirus



Reply | Threaded
Open this post in threaded view
|

Re: RES: Problem with FileSystem in WIndows

Sven Van Caekenberghe-2

> On 30 Apr 2017, at 19:31, Stephane Ducasse <[hidden email]> wrote:
>
> Can you open a bug entry with clear examples?
> We should improve this part.
> After having the interpretation of strings sucks. I do not like it I prefer
>
> FileLocator C / 'temp' / 'e8720bb4-b90a-0d00-9b1f-008709e5552b.txt'

Indeed.

Also, you should never have to write the platform test, an important idea of FileSystem is to prevent that.

Have you read the chapter on FileSystem from the Deep Into Pharo book ?

Maybe some Windows users can help you better, but I don't recall others having trouble using FileSystem on Windows.

> On Sun, Apr 30, 2017 at 6:54 PM, Casimiro de Almeida Barreto <[hidden email]> wrote:
> Hello,
>
> -----Mensagem original-----
> De: Pharo-dev [mailto:[hidden email]] Em nome de Sven Van Caekenberghe
> Enviada em: domingo, 30 de abril de 2017 05:30
> Para: Pharo Development List <[hidden email]>
> Assunto: Re: [Pharo-dev] Problem with FileSystem in WIndows
>
>
> > On 30 Apr 2017, at 09:48, Max Leske <[hidden email]> wrote:
> >
> > Hi Casimiro,
> >
> > have you tried using normal slashes in the path name? FileSystem should convert those to system path delimiters automatically. So:
>
> It seems that FileSystem does not convert / into \ .
> ((FileSystem root) / 'c:\temp\tempfile.txt')  writeStream won´t work but...
> FileStream fileNamed: 'C:\temp\tempfile.txt' works ok.
>
> So... I could make it work for getting a stream both for Unix and Windows:
>
>         OSPlatform currentPlatformName = 'unix'
>         ifTrue: [
>                 [ str := (fs / fn) writeStream ] on: Exception do: [ ^ nil ] ]
>         ifFalse: [
>                 [ str := FileStream fileNamed: fn ] on: Exception do: [ ^ nil ] ].
>
> And to delete:
>
>         OSPlatform currentPlatformName = 'unix'
>         ifTrue: [
>                 (FileSystem root / aFileName) delete ]
>         ifFalse: [
>                 rgx := RxMatcher forString: '^[A-Z]\:'.
>                 drive := rgx matchesIn: aFileName.
>                 drive := (drive at: 1) copyWithRegex: '\:' matchesReplacedWith: ''.
>                 ((FileLocator driveNamed: drive)  / (aFileName copyWithRegex: '^[A-Z]\:' matchesReplacedWith: '')) delete ]
>
> Not good, nor elegant nor anything close to good transparent code but... works :'(
>
> >
> > C:/temp/e8720bb4-b90a-0d00-9b1f-008709e5552b.txt
> >
> > And possibly you'll need a leading slash, as "C:" is a reference to the root of the file system:
> >
> > /C:/temp/e8720bb4-b90a-0d00-9b1f-008709e5552b.txt
>
> There is also the following option:
>
>         FileLocator C / 'temp' / 'e8720bb4-b90a-0d00-9b1f-008709e5552b.txt'
>
> > Cheers,
> > Max
> >
> >> On 30 Apr 2017, at 03:15, Casimiro de Almeida Barreto <[hidden email]> wrote:
> >>
> >> Good night all.
> >>
> >> I´ve had trouble in windows concerning FileSystem.
> >>
> >> ((FileSystem disk root) / ‘C:\temp\e8720bb4-b90a-0d00-9b1f-008709e5552b.txt’) delete
> >>
> >> Fails as if the file didn´t exist. Message:
> >>
> >> FileDoesNotExist: Path / ‘C:\temp\e8720bb4-b90a-0d00-9b1f-008709e5552b.txt’
> >>
> >> And I wonder what´s wrong. Because it works in linux and MacOS.
> >>
> >> Trasncript show: ((FileSYstem disk root) / ‘C:\temp\e8720bb4-b90a-0d00-9b1f-008709e5552b.txt’)
> >>
> >> Returns:
> >>
> >> File @ C:\temp\e8720bb4-b90a-0d00-9b1f-008709e5552b.txt\
> >>
> >> And I wonder where the last \ came from and if is it that is messing all and how to fix things.
> >>
> >> Best regards,
> >>
> >> Casimiro Barreto
> >>
> >>      Livre de vírus. www.avast.com.
> >
>
>
>
>
> ---
> Este email foi escaneado pelo Avast antivírus.
> https://www.avast.com/antivirus
>
>
>


Reply | Threaded
Open this post in threaded view
|

RES: RES: Problem with FileSystem in WIndows

CdAB63
> Indeed.
>
> Also, you should never have to write the platform test, an important idea of FileSystem is to prevent that.
>

Complete transparency is not possible because the concepts of file system in Windows and Unix are different. While in Unix you have a continuous tree, in Windows you have the concept of drive or 'disk unity' (C: D: E: ...) and disjunct trees. Also in Unix you can have complex file names that include almost all characters while in Unix some characters cannot be used (like : )... Not to mention that file properties in Unix and Windows are not exactly the same, links are not the same, so on and so forth.

> Have you read the chapter on FileSystem from the Deep Into Pharo book ?
>
> Maybe some Windows users can help you better, but I don't recall others having trouble using FileSystem on Windows.

Best regards,

Casimiro Barreto


---
Este email foi escaneado pelo Avast antivírus.
https://www.avast.com/antivirus


Reply | Threaded
Open this post in threaded view
|

RES: RES: Problem with FileSystem in WIndows

CdAB63
In reply to this post by Stephane Ducasse-3

Clear example follows. By the way ‘/’ and ‘\’ are not interchangeable… in Windows FileSystem requires ‘\’ to work properly:

 

| fn l fileStream |

fn := 'temp\',UUIDGenerator next asString,'.txt'.

Transcript clear; show: fn; cr.

fileStream := ((FileSystem root) / fn) writeStream.

fileStream

ifNil: [ Transcript show: 'Fail to create writeStream'; cr ]

ifNotNil: [ Transcript show: 'Opened' ].

fileStream nextPutAll: 'Casimiro de Almeida Barreto'.

fileStream close.

fileStream := ((FileSystem root) / fn) readStream.

l := fileStream upToEnd.

Transcript show: l; cr.

((FileSystem root) / fn) delete.

 

This example creates a file named c:\temp\380cafd3-c80a-0d00-b117-0a8a049bf78d.txt and I was able to write ‘Casimiro de Almeida Barreto’ to it. And then open the file in the read mode and read ‘Casimiro de Almeida Barreto’ from it. But… ((FileSystem root) / fn) delete returns a: ‘FileDoesNotExist: Path /’temp\380cafd3-c80a-0d00-b117-0a8a049bf78d.txt’. Apparently the problem is at WindowsStore(DiskStore) delete:

 


Livre de vírus. www.avast.com.
Reply | Threaded
Open this post in threaded view
|

Re: RES: RES: Problem with FileSystem in WIndows

Sven Van Caekenberghe-2
I have a feeling that you are working on the wrong level, consider:

file := FileReference newTempFilePrefix: 'data' suffix: '.txt'.
file writeStreamDo: [ :out | out << 'Casimiro de Almeida Barreto' ].
file contents.
file ensureDelete.
file exists.

The #newTempFilePrefix:suffix: method uses 'FileLocator temp' as target directory, which will be different on different platforms.

The trick is to use these FileLocator locations, try 'FileLocator supportedOrigins', to have an abstract, cross platform starting point (except for the Windows drives, obviously). Then you construct directories using messages.

Remember, the whole image, file browser, file dialogs, they all work cross platform, so you can do so too.

> On 30 Apr 2017, at 21:37, Casimiro de Almeida Barreto <[hidden email]> wrote:
>
>> Clear example follows. By the way ‘/’ and ‘\’ are not interchangeable… in Windows FileSystem requires ‘\’ to work properly:
>>
>>  
>>
>> | fn l fileStream |
>>
>> fn := 'temp\',UUIDGenerator next asString,'.txt'.
>>
>> Transcript clear; show: fn; cr.
>>
>> fileStream := ((FileSystem root) / fn) writeStream.
>>
>> fileStream
>>
>> ifNil: [ Transcript show: 'Fail to create writeStream'; cr ]
>>
>> ifNotNil: [ Transcript show: 'Opened' ].
>>
>> fileStream nextPutAll: 'Casimiro de Almeida Barreto'.
>>
>> fileStream close.
>>
>> fileStream := ((FileSystem root) / fn) readStream.
>>
>> l := fileStream upToEnd.
>>
>> Transcript show: l; cr.
>>
>> ((FileSystem root) / fn) delete.
>>
>  
> This example creates a file named c:\temp\380cafd3-c80a-0d00-b117-0a8a049bf78d.txt and I was able to write ‘Casimiro de Almeida Barreto’ to it. And then open the file in the read mode and read ‘Casimiro de Almeida Barreto’ from it. But… ((FileSystem root) / fn) delete returns a: ‘FileDoesNotExist: Path /’temp\380cafd3-c80a-0d00-b117-0a8a049bf78d.txt’. Apparently the problem is at WindowsStore(DiskStore) delete:
>  
> <image001.jpg>
>
> Livre de vírus. www.avast.com.


Reply | Threaded
Open this post in threaded view
|

RES: RES: RES: Problem with FileSystem in WIndows

CdAB63
Thanks for the tip Sven.

-----Mensagem original-----
De: Pharo-dev [mailto:[hidden email]] Em nome de Sven Van Caekenberghe
Enviada em: domingo, 30 de abril de 2017 17:14
Para: Pharo Development List <[hidden email]>
Assunto: Re: [Pharo-dev] RES: RES: Problem with FileSystem in WIndows

I have a feeling that you are working on the wrong level, consider:

file := FileReference newTempFilePrefix: 'data' suffix: '.txt'.
file writeStreamDo: [ :out | out << 'Casimiro de Almeida Barreto' ].
file contents.
file ensureDelete.
file exists.

The #newTempFilePrefix:suffix: method uses 'FileLocator temp' as target directory, which will be different on different platforms.

The trick is to use these FileLocator locations, try 'FileLocator supportedOrigins', to have an abstract, cross platform starting point (except for the Windows drives, obviously). Then you construct directories using messages.

Remember, the whole image, file browser, file dialogs, they all work cross platform, so you can do so too.



---
Este email foi escaneado pelo Avast antivírus.
https://www.avast.com/antivirus


Reply | Threaded
Open this post in threaded view
|

Re: Problem with FileSystem in WIndows

alistairgrant
In reply to this post by CdAB63
On Sat, Apr 29, 2017 at 10:15:15PM -0300, Casimiro de Almeida Barreto wrote:

> Good night all.
>
> I?ve had trouble in windows concerning FileSystem.
>
> ((FileSystem disk root) / ?C:\temp\e8720bb4-b90a-0d00-9b1f-008709e5552b.txt?)
> delete
>
> Fails as if the file didn?t exist. Message:
>
> FileDoesNotExist: Path / ?C:\temp\e8720bb4-b90a-0d00-9b1f-008709e5552b.txt?
>
> And I wonder what?s wrong. Because it works in linux and MacOS.
>
> Trasncript show: ((FileSYstem disk root) / ?C:\temp\
> e8720bb4-b90a-0d00-9b1f-008709e5552b.txt?)
>
> Returns:
>
> File @ C:\temp\e8720bb4-b90a-0d00-9b1f-008709e5552b.txt\
>
> And I wonder where the last \ came from and if is it that is messing all and
> how to fix things.


This is partially related to the problem I reported in "FileReference /
and Parent" in that the filename isn't being parsed properly.  See:

http://forum.world.st/FileReference-and-parent-td4941066.html

Note that the patch I suggest in the email thread doesn't solve the
problem either.

The trailing slash in the example above is because the path isn't being
parsed, the windows file store thinks that there is only a single
segment, which means the drive, so must be a directory.

As a workaround, if you have a complete path string, try using
#asFileReference, e.g.:

'C:\temp\e8720bb4-b90a-0d00-9b1f-008709e5552b.txt' asFileReference exists


Cheers,
Alistair