If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
A %HOMEPATH% question - end with a backslash or not ?
Hello all,
I've been setting HOMEDRIVE and HOMEPATH on my local computer, and bumped into the following: Point to a drives root : "\" (you have to otherwise the environment variable disappears) Point to a folder "\foldername" (as shown when I googeled for it) In other words: The top one starts and ends with a backslash (even if they are the same one :-) ), the bottom one /doesn't/ end with one. And that creates a problem: When I append a folder or filename to the top one it should /not/ start with a backslash, but when I do the same for the bottom one it ofcourse goes quite wrong. Or I always start the appended folder or filename with a backslash, causing the bottom to go alright, but now the top one has got two backslashes ("C:\\filename.ext") - which could create problems elsewhere. As such I'm rather confused: Those above environment variables have been in use for quite a while now, but I've not seen any mentioning of the described problem. What gives - or maybe just: whats the solution ? Regards, Rudy Wieser |
Ads |
#2
|
|||
|
|||
A %HOMEPATH% question - end with a backslash or not ?
On Wed, 17 Apr 2019 17:55:10 +0200, R.Wieser wrote:
Hello all, I've been setting HOMEDRIVE and HOMEPATH on my local computer, and bumped into the following: Point to a drives root : "\" (you have to otherwise the environment variable disappears) Point to a folder "\foldername" (as shown when I googeled for it) In other words: The top one starts and ends with a backslash (even if they are the same one :-) ), the bottom one /doesn't/ end with one. And that creates a problem: When I append a folder or filename to the top one it should /not/ start with a backslash, but when I do the same for the bottom one it ofcourse goes quite wrong. Or I always start the appended folder or filename with a backslash, causing the bottom to go alright, but now the top one has got two backslashes ("C:\\filename.ext") - which could create problems elsewhere. As such I'm rather confused: Those above environment variables have been in use for quite a while now, but I've not seen any mentioning of the described problem. What gives - or maybe just: whats the solution ? Regards, Rudy Wieser I just checked on XP, Win7 and Win10, and HOMEPATH does NOT end with a backslash (when it is not the root directory) in any of these operating systems. Somehow, the rest of the world still survives. One solution is that before you append a folder or filename, you check whether what you are appending it to ends with a \ or not. -- Kind regards Ralph |
#3
|
|||
|
|||
A %HOMEPATH% question - end with a backslash or not ?
Ralph,
I just checked on XP, Win7 and Win10, and HOMEPATH does NOT end with a backslash (when it is not the root directory) in any of these operating systems. That confirms what I found myself. Thanks. One solution is that before you append a folder or filename, you check whether what you are appending it to ends with a \ or not. Thats not a viable solution for things like shortcuts or registry entries. And I'm not at all sure how that would work in batch files. Regards, Rudy Wieser |
#4
|
|||
|
|||
A %HOMEPATH% question - end with a backslash or not ?
On Wed, 17 Apr 2019 20:37:44 +0200, R.Wieser wrote:
One solution is that before you append a folder or filename, you check whether what you are appending it to ends with a \ or not. Thats not a viable solution for things like shortcuts or registry entries. And I'm not at all sure how that would work in batch files. One trick to append a path with another is by appending it with ".\" first, then append it with the other path. But only if the path being appended doesn't end with ".", such as "d:\abc\." or "d:\abc\..". If it does end with ".", it should be appended with "\.\" first (instead of ".\"). e.g. "d:" + ".\" + "dir\file.ext" = "d:.\dir\file.ext" = "d:dir\file.ext" "d:\" + ".\" + "dir\file.ext" = "d:\.\dir\file.ext" = "d:\dir\file.ext" "d:\abc" + ".\" + "dir\file.ext" = "d:\abc.\dir\file.ext" = "d:\abc\dir\file.ext" "d:\abc\" + ".\" + "dir\file.ext" = "d:\abc\.\dir\file.ext" = "d:\abc\dir\file.ext" "d:\abc\." + "\.\" + "dir\file.ext" = "d:\abc\.\.\dir\file.ext" = "d:\abc\dir\file.ext" "d:\abc\.." + "\.\" + "dir\file.ext" = "d:\abc\..\.\dir\file.ext" = "d:\dir\file.ext" These works on remote paths too. |
#5
|
|||
|
|||
A %HOMEPATH% question - end with a backslash or not ?
JJ,
But only if the path being appended doesn't end with ".", such as "d:\abc\." or "d:\abc\.." I would than just be exchanging one problem for another, wouldn't I ? :-p One trick to append a path with another is by appending it with ".\" first, then append it with the other path. A possible better (single point of change) trick would be to just set HOMEPATH on my home 'puter to "\." (slash, dot). That way I could go with the convention to preceede any to-be-added path-parts with a backslash and be done with it (and complain to the responsible IT manager if/when that (the preceeding backslash) doesn't work :-) ). The thing is that I can come up with those hacks myself too. But it still leaves me wondering about why I do not see the problem mentioned anywhere (and what the /conventions/ in regard to dealing with it are). Or, as I just realized the cause of my reluctance to use such hacks, I have absolutily /no/ idea if they work /everywhere/ . Experience tells me that they work in batchfiles, and just checked and noticed they work in shortcuts too. But all the other places they could be used at (inside programs I have zero control over) ? No idea ... :-( Regards, Rudy Wieser |
#6
|
|||
|
|||
A %HOMEPATH% question - end with a backslash or not ?
JJ,
Or, as I just realized the cause of my reluctance to use such hacks, I have absolutily /no/ idea if they work /everywhere/ . I just noticed a side-effect that currently doesn't seem to outright break anything, but doesn't look nice either. When starting my command console I add some stuff to the PATH variable, using the HOMEDRIVE and HOMEPATH variables. Which now looks like "...;C:\.\folder;..." :-( Regards, Rudy Wieser |
#7
|
|||
|
|||
A %HOMEPATH% question - end with a backslash or not ?
On Wed, 17 Apr 2019 20:37:44 +0200, R.Wieser wrote:
Ralph, One solution is that before you append a folder or filename, you check whether what you are appending it to ends with a \ or not. Thats not a viable solution for things like shortcuts or registry entries. And I'm not at all sure how that would work in batch files. Batch files Here is how to do it. SETLOCAL ENABLEEXTENSIONS SET FILEPATH=%HOMEDRIVE%%HOMEPATH%\myfile.txt SET FILEPATH=%FILEPATH:\\=\% Shortcuts or registry entries Here is how to do it. Have the shortcut or registry entry point to a batch file which first converts a \\ to \ and then chains to the real program. -- Kind regards Ralph ðŸ˜*🞂😢🞂😯🞂🤔🞂😌🞂😃 |
#8
|
|||
|
|||
A %HOMEPATH% question - end with a backslash or not ?
Ralph,
SETLOCAL ENABLEEXTENSIONS SET FILEPATH=%HOMEDRIVE%%HOMEPATH%\myfile.txt SET FILEPATH=%FILEPATH:\\=\% Yep, I was already looking for a sulution like that (but was fumbling around with %~f ). And it seems to work even without the first line. Thanks. Looks a /lot/ better that way. Though the batch environment has no clue how to deal with it when those second and third lines are combined into a single one. grumblegrumblestupidthinggrumble :-\ :-) Shortcuts or registry entries Here is how to do it. Have the shortcut or registry entry point to a batch file which first converts a \\ to \ and then chains to the real program. :-) Not really a viable fix I'm afraid. Apart from possibly having /many/ entries to apply it to (and not all of them interceptable that way), the (direct) parent-child relation of the programs will be broken by it, possibly causing new problems ... (bumped into that one myself when I thought of a way to have files with certain extensions in one folder being given to a one program, and in another folder to a second program) Regards, Rudy Wieser |
#9
|
|||
|
|||
A %HOMEPATH% question - end with a backslash or not ?
On Thu, 18 Apr 2019 10:11:45 +0200, R.Wieser wrote:
JJ, Or, as I just realized the cause of my reluctance to use such hacks, I have absolutily /no/ idea if they work /everywhere/ . I just noticed a side-effect that currently doesn't seem to outright break anything, but doesn't look nice either. When starting my command console I add some stuff to the PATH variable, using the HOMEDRIVE and HOMEPATH variables. Which now looks like "...;C:\.\folder;..." :-( Well, you'll have to replace "\.\" with "\", before appending it to the PATH variable. e.g. set dir=C:\.\folder set path=%path%;%dir:\.\=\% |
#10
|
|||
|
|||
A %HOMEPATH% question - end with a backslash or not ?
JJ,
Well, you'll have to replace "\.\" with "\", before appending it to the PATH variable. e.g. set dir=C:\.\folder set path=%path%;%dir:\.\=\% Ralph mentioned the same solution for it (I was looking at how to get %~f to do it, and failed). I had no idea that that string-replace command existed in XP. Now I only need to believe that that "\." (slahs, dot) in the homepath variable won't cause problems elsewhere ... (I'm currently trying it out on a test machine). Regards, Rudy Wieser "JJ" wrote in message ... On Thu, 18 Apr 2019 10:11:45 +0200, R.Wieser wrote: JJ, Or, as I just realized the cause of my reluctance to use such hacks, I have absolutily /no/ idea if they work /everywhere/ . I just noticed a side-effect that currently doesn't seem to outright break anything, but doesn't look nice either. When starting my command console I add some stuff to the PATH variable, using the HOMEDRIVE and HOMEPATH variables. Which now looks like "...;C:\.\folder;..." :-( Well, you'll have to replace "\.\" with "\", before appending it to the PATH variable. e.g. set dir=C:\.\folder set path=%path%;%dir:\.\=\% |
Thread Tools | |
Display Modes | |
|
|