XP command line to go to current user's folders

S0Y73NTGR33N

Senior member
Sep 27, 2004
420
0
0
Is there a way to write a command line to go to the current users documents and settings folder?

like normally I would go

cd documents and settings\soylentgreen

but I want a line to be able to open up the current users folder if it is a different user.

?

-green
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
Windows is a multi-user OS (for the most part) so there's no 'current user', for example if TS is enabled there could be dozens of current users. Yes, there is only one console user, but I don't know of a way to figure out who it is off the top of my head.
 

Zugzwang152

Lifer
Oct 30, 2001
12,134
1
0
cd "c:\documents and settings\%username%"

link to the rest of the windows xp environment variables. Scroll down or do a find for the "Using environment variables with Cmd.exe" section.
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
%username% ?

Only if it's your session, if you're attaching from a remote machine that won't work. Also I think there's %USERDIR% or something that has the full profile path, incase it's not c:\documents and settings\%username%
 

S0Y73NTGR33N

Senior member
Sep 27, 2004
420
0
0
Yes %username% worked but it doesn't work in perl so I had to make a perl command like this....

system 'explorer.exe c:\documents and settings\%username%... etc....

thanks a lot for the help

-green
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
You can use environment variables in perl, you just need to use the %ENV hash.
 

S0Y73NTGR33N

Senior member
Sep 27, 2004
420
0
0
So I'm having trouble using %ENV.

what I want to do is make Perl print the spybot log file.

my script is like this.

print "Spybot is scanning please wait...\n";
system 'spyware\spybot\SpybotSd.exe /autocheck /autofix /taskbarhide /autoclose';
print "Spybot has finished scanning please\n",
"press <Enter> to review the log file\n";
<STDIN>;
<STDIN>;
open (FILEHANDLE, $ENV{USERPROFILE}, '\Application data\Spybot~1\logs\checks.log') or
die ("Cannot open Spybot log file.");
$text = "";
while (read (FILEHANDLE, $newtext, 1))
{
$text .= $newtext;
}
print $text,
"Thanks for running Spybot\n
Press <Enter> to continue...";
<STDIN>;


what am I doing wrong?

-green
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
You're using open wrong. The 3 argument version takes filehandle, mode, filename. So you would want open(FH, '<', "$ENV{USERPROFILE}\Application Data\Spybot~1\logs\checks.log")

You also might have to escape the backslashes since they're usually used to denote special characters, but I'm not sure about that since I usually use perl on OSes with sane directory seperators =)