Hi everyone, I'm trying to rename files with this code but it doesn't work, pharo is saying me "PrimitiveFailed" I tried lots of things and I'm not finding how I can rename this file, someone has an idea please? | myFile | myFile := FileSystem root / 'aPath/cat.jpg'. myFile renameTo:'cats.jpg' Valentin
Hi Valentin,
On 18 Apr 2016, at 10:31, Valentin Ryckewaert <valentin.ryckewaert@gmail.com> wrote:
Hi everyone,
I'm trying to rename files with this code but it doesn't work, pharo is saying me "PrimitiveFailed" I tried lots of things and I'm not finding how I can rename this file, someone has an idea please?
| myFile | myFile := FileSystem root / 'aPath/cat.jpg'. myFile renameTo:'cats.jpg'
Valentin
Seems to work OK for me (Pharo 5 on Mac OS) '/tmp/foo.txt' asFileReference writeStreamDo: [ :out | out << 'Pharo' ]. '/tmp/foo.txt' asFileReference exists. '/tmp/foo.txt' asFileReference renameTo: 'bar.txt'. '/tmp/foo.txt' asFileReference exists. '/tmp/bar.txt' asFileReference exists. '/tmp/bar.txt' asFileReference contents. Maybe a permission problem ? Sven
Using your method (A string asFileReference) it works thanks ! But if you use FileSystem root / .... I get the "same" object but it's still not working. Did I make a mistake somewhere? 2016-04-18 10:38 GMT+02:00 Sven Van Caekenberghe <sven@stfx.eu>:
Hi Valentin,
On 18 Apr 2016, at 10:31, Valentin Ryckewaert < valentin.ryckewaert@gmail.com> wrote:
Hi everyone,
I'm trying to rename files with this code but it doesn't work, pharo is saying me "PrimitiveFailed" I tried lots of things and I'm not finding how I can rename this file, someone has an idea please?
| myFile | myFile := FileSystem root / 'aPath/cat.jpg'. myFile renameTo:'cats.jpg'
Valentin
Seems to work OK for me (Pharo 5 on Mac OS)
'/tmp/foo.txt' asFileReference writeStreamDo: [ :out | out << 'Pharo' ].
'/tmp/foo.txt' asFileReference exists.
'/tmp/foo.txt' asFileReference renameTo: 'bar.txt'.
'/tmp/foo.txt' asFileReference exists.
'/tmp/bar.txt' asFileReference exists.
'/tmp/bar.txt' asFileReference contents.
Maybe a permission problem ?
Sven
On 18/04/2016 10:44, Valentin Ryckewaert wrote:
Using your method (A string asFileReference) it works thanks !
But if you use FileSystem root / .... I get the "same" object but it's still not working. Did I make a mistake somewhere?
Hi, Did you try `FileSystem root / 'a' / 'Path' / 'cat.jpg'` instead of `FileSystem root / 'aPath/cat.jpg'`? On what OS are you? I remember I had some trouble with the root on Windows. -- Cyril Ferlicot http://www.synectique.eu 165 Avenue Bretagne Lille 59000 France
I'm on Linux Is it wanted that root / 'a' / 'foo.txt' is different than root / '.foo.txt' ? I find that strange 2016-04-18 10:52 GMT+02:00 Cyril Ferlicot Delbecque < cyril.ferlicot@gmail.com>:
On 18/04/2016 10:44, Valentin Ryckewaert wrote:
Using your method (A string asFileReference) it works thanks !
But if you use FileSystem root / .... I get the "same" object but it's still not working. Did I make a mistake somewhere?
Hi,
Did you try `FileSystem root / 'a' / 'Path' / 'cat.jpg'` instead of `FileSystem root / 'aPath/cat.jpg'`?
On what OS are you? I remember I had some trouble with the root on Windows.
-- Cyril Ferlicot
165 Avenue Bretagne Lille 59000 France
On 18/04/2016 10:56, Valentin Ryckewaert wrote:
I'm on Linux
Is it wanted that root / 'a' / 'foo.txt' is different than root / '.foo.txt' ? I find that strange
If you want a relative path from the image location you can use `FileSystem workingDirectory / 'foo.txt'` -- Cyril Ferlicot http://www.synectique.eu 165 Avenue Bretagne Lille 59000 France
You can also use String>>asFileReference: relative path: './foo.txt' asFileReference absolute path: '/foo.txt' asFileReference Cheers, Doru
On Apr 18, 2016, at 11:01 AM, Cyril Ferlicot Delbecque <cyril.ferlicot@gmail.com> wrote:
On 18/04/2016 10:56, Valentin Ryckewaert wrote:
I'm on Linux
Is it wanted that root / 'a' / 'foo.txt' is different than root / '.foo.txt' ? I find that strange
If you want a relative path from the image location you can use `FileSystem workingDirectory / 'foo.txt'`
-- Cyril Ferlicot
165 Avenue Bretagne Lille 59000 France
-- www.tudorgirba.com www.feenk.com "Presenting is storytelling."
Think of it as follows: Pharo is cross platform, forward slash is used on *nix and Mac OS, but not Windows where it is backslash. FileReference is an object oriented API that abstracts over that. Asking for an interpretation of the sub parts is a step too far (even if it would be handy).
On 18 Apr 2016, at 10:56, Valentin Ryckewaert <valentin.ryckewaert@gmail.com> wrote:
I'm on Linux
Is it wanted that root / 'a' / 'foo.txt' is different than root / '.foo.txt' ? I find that strange
2016-04-18 10:52 GMT+02:00 Cyril Ferlicot Delbecque <cyril.ferlicot@gmail.com>:
On 18/04/2016 10:44, Valentin Ryckewaert wrote:
Using your method (A string asFileReference) it works thanks !
But if you use FileSystem root / .... I get the "same" object but it's still not working. Did I make a mistake somewhere?
Hi,
Did you try `FileSystem root / 'a' / 'Path' / 'cat.jpg'` instead of `FileSystem root / 'aPath/cat.jpg'`?
On what OS are you? I remember I had some trouble with the root on Windows.
-- Cyril Ferlicot
165 Avenue Bretagne Lille 59000 France
Ok thanks everyone for your answers I got it ! :) 2016-04-18 11:08 GMT+02:00 Sven Van Caekenberghe <sven@stfx.eu>:
Think of it as follows: Pharo is cross platform, forward slash is used on *nix and Mac OS, but not Windows where it is backslash. FileReference is an object oriented API that abstracts over that. Asking for an interpretation of the sub parts is a step too far (even if it would be handy).
On 18 Apr 2016, at 10:56, Valentin Ryckewaert < valentin.ryckewaert@gmail.com> wrote:
I'm on Linux
Is it wanted that root / 'a' / 'foo.txt' is different than root / '.foo.txt' ? I find that strange
2016-04-18 10:52 GMT+02:00 Cyril Ferlicot Delbecque < cyril.ferlicot@gmail.com>:
On 18/04/2016 10:44, Valentin Ryckewaert wrote:
Using your method (A string asFileReference) it works thanks !
But if you use FileSystem root / .... I get the "same" object but it's still not working. Did I make a mistake somewhere?
Hi,
Did you try `FileSystem root / 'a' / 'Path' / 'cat.jpg'` instead of `FileSystem root / 'aPath/cat.jpg'`?
On what OS are you? I remember I had some trouble with the root on Windows.
-- Cyril Ferlicot
165 Avenue Bretagne Lille 59000 France
2016-04-18 11:08 GMT+02:00 Sven Van Caekenberghe <sven@stfx.eu>:
Think of it as follows: Pharo is cross platform, forward slash is used on *nix and Mac OS, but not Windows where it is backslash. FileReference is an object oriented API that abstracts over that. Asking for an interpretation of the sub parts is a step too far (even if it would be handy).
We have an open bugtracker issue about this. There is no conclusion right now how to handle this. I understand that this path interpretation is a step too far , on the other hand we already do this in #resolveString: see output of (on a windows platform(!)) (FileSystem root / 'aPath/file.txt') basename. (FileSystem root / 'aPath\file.txt') basename. vs. (FileSystem root resolveString:'aPath/file.txt') basename. (FileSystem root resolveString:'aPath\file.txt') basename. #/ could behave like #resolveString And for example: (FileLocator vmDirectory / 'testdir/file.txt') writeStream << 'Test' will succeed, if the directory <vmdirectory>/testdir/ exists (it does not try to create a file called "testdir/file.txt", but really just "file.txt"). (see issue 13217)
On 18 Apr 2016, at 10:56, Valentin Ryckewaert < valentin.ryckewaert@gmail.com> wrote:
I'm on Linux
Is it wanted that root / 'a' / 'foo.txt' is different than root / '.foo.txt' ? I find that strange
2016-04-18 10:52 GMT+02:00 Cyril Ferlicot Delbecque < cyril.ferlicot@gmail.com>:
On 18/04/2016 10:44, Valentin Ryckewaert wrote:
Using your method (A string asFileReference) it works thanks !
But if you use FileSystem root / .... I get the "same" object but it's still not working. Did I make a mistake somewhere?
Hi,
Did you try `FileSystem root / 'a' / 'Path' / 'cat.jpg'` instead of `FileSystem root / 'aPath/cat.jpg'`?
On what OS are you? I remember I had some trouble with the root on Windows.
-- Cyril Ferlicot
165 Avenue Bretagne Lille 59000 France
An interresting fact is that exists answer true to (FileSystem root / 'aPath/cat.jpg') exists 2016-04-18 11:25 GMT+02:00 Nicolai Hess <nicolaihess@gmail.com>:
2016-04-18 11:08 GMT+02:00 Sven Van Caekenberghe <sven@stfx.eu>:
Think of it as follows: Pharo is cross platform, forward slash is used on *nix and Mac OS, but not Windows where it is backslash. FileReference is an object oriented API that abstracts over that. Asking for an interpretation of the sub parts is a step too far (even if it would be handy).
We have an open bugtracker issue about this. There is no conclusion right now how to handle this. I understand that this path interpretation is a step too far , on the other hand we already do this in #resolveString:
see output of (on a windows platform(!))
(FileSystem root / 'aPath/file.txt') basename. (FileSystem root / 'aPath\file.txt') basename.
vs.
(FileSystem root resolveString:'aPath/file.txt') basename. (FileSystem root resolveString:'aPath\file.txt') basename.
#/ could behave like #resolveString
And for example:
(FileLocator vmDirectory / 'testdir/file.txt') writeStream << 'Test'
will succeed, if the directory <vmdirectory>/testdir/ exists (it does not try to create a file called "testdir/file.txt", but really just "file.txt").
(see issue 13217)
On 18 Apr 2016, at 10:56, Valentin Ryckewaert < valentin.ryckewaert@gmail.com> wrote:
I'm on Linux
Is it wanted that root / 'a' / 'foo.txt' is different than root / '.foo.txt' ? I find that strange
2016-04-18 10:52 GMT+02:00 Cyril Ferlicot Delbecque < cyril.ferlicot@gmail.com>:
On 18/04/2016 10:44, Valentin Ryckewaert wrote:
Using your method (A string asFileReference) it works thanks !
But if you use FileSystem root / .... I get the "same" object but it's still not working. Did I make a mistake somewhere?
Hi,
Did you try `FileSystem root / 'a' / 'Path' / 'cat.jpg'` instead of `FileSystem root / 'aPath/cat.jpg'`?
On what OS are you? I remember I had some trouble with the root on Windows.
-- Cyril Ferlicot
165 Avenue Bretagne Lille 59000 France
Hi, I think the problem is using 'aPath/cat.jpg' as a single string (= as a single component of the path). This: path1 := FileSystem root / 'a/b/c.txt'. is different to: path2 := FileSystem root / 'a' / 'b' / 'c.txt'. Compare the results when I ask for the parent directory: path1 parent "-> File @ /" path2 parent "-> File @ /a/b" When renaming, the #renameTo: method takes the #parent directory as the base for the target filename. Therefore: (FileSystem root / 'a/b/c.txt') renameTo: 'my.txt'. will try to create file: FileSystem root / 'my.txt' Whereas: (FileSystem root / 'a' / 'b' / 'c.txt') renameTo: 'my.txt'. will try to create file: FileSystem root / 'a' / 'b' / 'my.txt' And in your case, FileSystem root is probably not writable. Michal On 18.4.2016 10:31, Valentin Ryckewaert wrote:
Hi everyone,
I'm trying to rename files with this code but it doesn't work, pharo is saying me "PrimitiveFailed" I tried lots of things and I'm not finding how I can rename this file, someone has an idea please?
| myFile | myFile := FileSystem root / 'aPath/cat.jpg'. myFile renameTo:'cats.jpg'
Valentin
participants (6)
-
Cyril Ferlicot Delbecque -
Michal Balda -
Nicolai Hess -
Sven Van Caekenberghe -
Tudor Girba -
Valentin Ryckewaert