- NSIS Discussion
- How to 'normalize' file path?
Archive: How to 'normalize' file path?
Yurik
5th August 2005 12:34 UTC
How to 'normalize' file path?
The problem with long paths came back.
I write the following line:
File /r "..\..\..\..\..\bin\JBossSources\*.*"
and this leads to file paths exceeding 255.
How can I transform this relative path to absolute path without '..\'?
Joost Verburg
5th August 2005 13:12 UTC
This one might help in combination with the System plug-in.
http://msdn.microsoft.com/library/de...nonicalize.asp
RobGrant
5th August 2005 13:17 UTC
This sort of depends on how much you know about the directory structure.
E.g. If the path ends up as: "C:\Program Files\Miscellaneous\Keep\Productname\Files\Exe\bin\JbossSources\", and you know everything from Productname onwards, then you can simply get the current path (using GetFullPathName) and remove the requisite number of characters to find the path you want.
So if you wanted to put files into "C:\Program Files\Miscellaneous\Keep\Productname" and you're in "C:\Program Files\Miscellaneous\Keep\Productname\Files\Exe\bin\JbossSources\":
GetFullPathName $0 "."
StrLen $1 $0
IntOp $1 $1-27
StrCpy $0 $0 $1
That'd shorten the full pathname by 27 characters (ie. "\Files\Exe\bin\JbossSources\") and give you the required path.
Comperio
5th August 2005 17:15 UTC
In some of my VBScripts, I use a call to 'System.FileSystemObject' that allows me to get the short path of any path. system.FileSystemObject is contained in SCRRUN.DLL, which gets registered with the Windows Scripting Host.
The function returns a DOS file name using the 8.3 format. (using tildes ("~") to truncate file names longer than 8 characters. For example, "C:\Program files" would usually return "C:\Progra~1".
Problem is, I'm not sure if there is anything similiar that could be called via NSIS. (I was thinking that perhaps this is also a file property setting you might be able to read with the proper plugin, but I'm not 100% sure.)
PS: if you need an example of a VBScript function, let me know.
Yurik
8th August 2005 12:50 UTC
BTW, I thought a little and decided that actually it is NSIS problem, not mine. I'm providing NSIS with the correct (relative) path, and absolute path to my files is within 255, so why should I be aware that NSIS is not smart enough and just concatenates current folder and relative path? I shouldn't be aware of this inside implementation details. Moreover - even now I'm just guessing why the error occurs.
My proposal is to implement paths canonization within NSIS itself.
Yurik
8th August 2005 16:10 UTC
Can't use PathCanonicalize since this could be called in runtime, but my problem is compile-time.
stb
9th August 2005 10:00 UTC
@Comperio: There is an API function (GetShortPathName) which can be called by NSIS/System.dll to get the short filename. But be aware that there may exist files which don't have a short filename under some filesystems (had this problem with Windows 2000 and NTFS).
Yurik
9th August 2005 10:04 UTC
It is useful as long as being called in runtime. The error I'm getting is occured on File statement in compile-time.
stb
9th August 2005 10:09 UTC
@Yurik: I know. I don't have your problem, but I agree NSIS should normalize path on compile time. You may build a workaround using "!cd".
Yurik
9th August 2005 10:10 UTC
thanks, stb, I will try!
RobGrant
9th August 2005 14:07 UTC
Ooh.
If you want to be quick about it, write a program in C or C++ or Perl or something that splits the path down into / (or \)-separated chunks, then checks the length of each chunk and truncates it if necessary?
P.S. this can be done in NSIS.
Yurik
9th August 2005 14:23 UTC
Thank, RobGrant. For now I've made a simple thing - before calling my script which is performed from a batch file, I normalize the path using batch commands (%~f1) and pass the result to the script as a define. But I hope later it will be implemented in NSIS.