I am using FileRequest in my program, and then save the result to be used later, however, I just realised that instead of having relative path, like "Pictures/filename.img" it is actually saving them as "C://hollywoodprogs/Pictures/Filename.img", and I am now wondering if there is some simple way, a command to have the relative path instead of the full path when using FileRequest.
Like I would like it to start from the directory where program is started from, and then save relative path from that point when I use filerequest.
I can see there is PathPart(), FilePart(), and GetCurrentDirectory(), but is there anything like RelativePathPart() existing, or do I have to make one myself using PathPart() and GetCurrentDirectory()? I am mainly worried that doing one myself could result in unexpected behavior when using program in different machines/directories.
Way to get relative pathpart of a file?
Re: Way to get relative pathpart of a file?
Afaik no there is no. Must use currentdir to remove ot from filepart
But why tou worry about inexpected behaviour in oses?
Hollywood takes care of that...
But why tou worry about inexpected behaviour in oses?
Hollywood takes care of that...
Christos
Re: Way to get relative pathpart of a file?
In this case there probably isnt going to be problems, but just that I was able to already see possible problems that could happen if realising these problems too late, like the following, where GetCurrentDirectory() cant fix the problem anymore, although, I doubt specific command to take the relative path could solve it anymore either.
I have this editor where I pick pictures and then it saves their paths (only now realised it is actually saving full path instead of relative path), so first I use it in c:HollywoodProgs and all pictures are C:HollywoodProgs/Pictures/name.jpg
then I move it to c:MyprogramName and notice pictures are not loading. So I decide to remove all the names, So I take the CurrentDirectory, which is now C:MyProgramName instead of C:HollywoodProgs, and then I use ReplaceStr with idea that I want to leave only the relative part of the path, except, it is now looking for C:MyProgramName, instead of C:HollywoodProgs, and hence it doesn't find, nor fix them, and problem stays.
Similarly if I saved them in Amiga and then started modifying in Amiga, I could run into similar kind of problem with "/" and "\" in that when using FindStr() it wouldn't find when it should, if I would for some reason need to alter them in masses using FindStr.
Figuring out those comes to mind that there could be some other, more relevant cases too that just don't come to my mind, but basically I do think that GetCurrentDirectory() is enough of a solution to my current problem.
I have this editor where I pick pictures and then it saves their paths (only now realised it is actually saving full path instead of relative path), so first I use it in c:HollywoodProgs and all pictures are C:HollywoodProgs/Pictures/name.jpg
then I move it to c:MyprogramName and notice pictures are not loading. So I decide to remove all the names, So I take the CurrentDirectory, which is now C:MyProgramName instead of C:HollywoodProgs, and then I use ReplaceStr with idea that I want to leave only the relative part of the path, except, it is now looking for C:MyProgramName, instead of C:HollywoodProgs, and hence it doesn't find, nor fix them, and problem stays.
Similarly if I saved them in Amiga and then started modifying in Amiga, I could run into similar kind of problem with "/" and "\" in that when using FindStr() it wouldn't find when it should, if I would for some reason need to alter them in masses using FindStr.
Figuring out those comes to mind that there could be some other, more relevant cases too that just don't come to my mind, but basically I do think that GetCurrentDirectory() is enough of a solution to my current problem.
Re: Way to get relative pathpart of a file?
@Bugala
If I understood you correctly, the folder "Pictures" is always inside your program's folder, which is the current folder, right?
In that case I think using a variable for the path could help you. Something like this at the start of your script (haven't tested):
Then you join myDirectory$ with the filename for the full path and name. And if you move your program to another location it should still work.
If I understood you correctly, the folder "Pictures" is always inside your program's folder, which is the current folder, right?
In that case I think using a variable for the path could help you. Something like this at the start of your script (haven't tested):
Code: Select all
If #HW_AMIGA
myDirectory$=GetCurrentDirectory().."/Pictures/"
ElseIf #HW_LINUX
myDirectory$=GetCurrentDirectory().."/Pictures/"
ElseIf #HW_WINDOWS
myDirectory$=GetCurrentDirectory().."\Picture\"
EndIf
PowerBook 5.8 MorphOS 3.18
Mac Mini MorphOS 3.18
Mac Mini MorphOS 3.18
Re: Way to get relative pathpart of a file?
Basically yes. However, I might one day release it for others to use too, at which point cant know where it is anymore, so at that point have to use the GetCurrentDirectory option and remove the beginning, plus actually one more letter I noticed. For GetCurrentDirectory() gives you something like:
C://progs
while full path is:
C://progrs/pictures
which means that comparing and removing using GetCurrentDirectory, would still leave /pictures as the end result.
And depending what OS you are using, depends what that "/" is, for which reason I came to conclusion of using StrToArray, then removeItem from position 0 and ArrayToStr again and this way be able to remove the leftover slash, regardless which way it is.
But shows that there are enough moving parts in this that RelativePathPart() command would be useful and more future proof way of doing it.
C://progs
while full path is:
C://progrs/pictures
which means that comparing and removing using GetCurrentDirectory, would still leave /pictures as the end result.
And depending what OS you are using, depends what that "/" is, for which reason I came to conclusion of using StrToArray, then removeItem from position 0 and ArrayToStr again and this way be able to remove the leftover slash, regardless which way it is.
But shows that there are enough moving parts in this that RelativePathPart() command would be useful and more future proof way of doing it.