A Windows XP help forum. PCbanter

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.

Go Back   Home » PCbanter forum » Microsoft Windows XP » General XP issues or comments
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

A %HOMEPATH% question - end with a backslash or not ?



 
 
Thread Tools Display Modes
  #1  
Old April 17th 19, 04:55 PM posted to microsoft.public.windowsxp.general
R.Wieser
external usenet poster
 
Posts: 1,302
Default 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  
Old April 17th 19, 07:14 PM posted to microsoft.public.windowsxp.general
Ralph Fox
external usenet poster
 
Posts: 474
Default 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  
Old April 17th 19, 07:37 PM posted to microsoft.public.windowsxp.general
R.Wieser
external usenet poster
 
Posts: 1,302
Default 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  
Old April 18th 19, 03:53 AM posted to microsoft.public.windowsxp.general
JJ[_11_]
external usenet poster
 
Posts: 744
Default 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  
Old April 18th 19, 08:46 AM posted to microsoft.public.windowsxp.general
R.Wieser
external usenet poster
 
Posts: 1,302
Default 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  
Old April 18th 19, 09:11 AM posted to microsoft.public.windowsxp.general
R.Wieser
external usenet poster
 
Posts: 1,302
Default 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  
Old April 18th 19, 09:41 AM posted to microsoft.public.windowsxp.general
Ralph Fox
external usenet poster
 
Posts: 474
Default 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  
Old April 18th 19, 10:04 AM posted to microsoft.public.windowsxp.general
R.Wieser
external usenet poster
 
Posts: 1,302
Default 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  
Old April 19th 19, 06:40 AM posted to microsoft.public.windowsxp.general
JJ[_11_]
external usenet poster
 
Posts: 744
Default 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  
Old April 19th 19, 07:19 AM posted to microsoft.public.windowsxp.general
R.Wieser
external usenet poster
 
Posts: 1,302
Default 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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off






All times are GMT +1. The time now is 07:54 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 PCbanter.
The comments are property of their posters.