Connecting Tech Pros Worldwide Forums | Help | Site Map

%USERPROFILE% - What is this?

Member
 
Join Date: Sep 2007
Location: Virginia Beach, VA
Posts: 57
#1: Nov 28 '07
Hello All,
I have Perl code that looks like the following. $file is pointing to a directory on the C: drive that has 2 text files in it (let's say text_file_name1.txt and text_file_name2.txt).The lines of code to print out the names of the text files in the directory are:

[HTML]foreach $file(@result_files)
{
print "$file\n";
}[/HTML]

Can someone tell me why the print out gives me this:

C:/%USERPROFILE$
C:/text_file_name1.txt
C:/text_file_name2.txt

What is %USERPROFILE$? And why is it showing up???

Terra

KevinADC's Avatar
Expert
 
Join Date: Jan 2007
Location: Southern California USA
Posts: 4,091
#2: Nov 28 '07

re: %USERPROFILE% - What is this?


might be a file that is usually hidden from the user but perl picks it up.
numberwhun's Avatar
Site Moderator
 
Join Date: May 2007
Location: New Hampshire
Posts: 2,571
#3: Nov 28 '07

re: %USERPROFILE% - What is this?


If you go into your file system browser and go to Tools->Folder Options, then go to the view tab in the window that appears, there is an option to "Show hidden files and folders". Select that radio button, hit Ok, and go to the folder and see what is there.

Regards,

Jeff
Member
 
Join Date: Sep 2007
Location: Virginia Beach, VA
Posts: 57
#4: Nov 29 '07

re: %USERPROFILE% - What is this?


Thank you for your responses. i went into the Options folder and selected the ' Show hidden files and folders'. nothing showed up in my folder except the files that i expected. but Perl still picks up the %USERPROFILE%. Interesting.

Is there a way for Perl to ignore it? I tried to use shift(), which removes the first element in the array (and i thought it wouldd remove the %USERPROFILE% since it shows up first), but it didn't, it removed the first real file in my folder that i need to keep and kept printing the %USERPROFILE%.

This %USERPROFILE% is really messing up my overall script!!!

Help please!!
Member
 
Join Date: Sep 2007
Location: Virginia Beach, VA
Posts: 57
#5: Nov 29 '07

re: %USERPROFILE% - What is this?


Here's a follow up to my previous reply...

I found a line that is supposed to ignore hidden files:

[HTML]next if $file =~ /^\./;[/HTML]

But Perl is still printing out the hidden file %USERPROFILE%. Does anyone know if this is close to being correct?


However, i think that %USERPROFILE% is a Windows Environment Variable, that should be dealt with differently than a hidden file...

Terra
eWish's Avatar
Moderator
 
Join Date: Jul 2007
Location: Arkansas
Posts: 900
#6: Nov 29 '07

re: %USERPROFILE% - What is this?


See if this works for you.

Expand|Select|Wrap|Line Numbers
  1. foreach my $file (@array) {
  2.     next if $file =~ (/^\%/);
  3.     print $file, "\n";
  4. }
--Kevin
Member
 
Join Date: Sep 2007
Location: Virginia Beach, VA
Posts: 57
#7: Nov 29 '07

re: %USERPROFILE% - What is this?


Well,
I figured out a solution, unless there is a better way to do it.

This line of code skips over the %USERPROFILE% hidden file as it goes through the array:

[HTML]foreach $file(@result_files)
{
next if $file eq 'C:\Folder Name\%USERPROFILE%';
print "$file\n";
}[/HTML]

It works, so i'm happy!

Terra
numberwhun's Avatar
Site Moderator
 
Join Date: May 2007
Location: New Hampshire
Posts: 2,571
#8: Nov 29 '07

re: %USERPROFILE% - What is this?


Quote:

Originally Posted by Perl Beginner

Well,
I figured out a solution, unless there is a better way to do it.

This line of code skips over the %USERPROFILE% hidden file as it goes through the array:

foreach $file(@result_files)
{
next if $file eq 'C:\Folder Name\%USERPROFILE%';
print "$file\n";
}

It works, so i'm happy!

Terra

Thank you for letting us know! Thanks for assisting the OP with this problem eWish!

Regards,

Jeff
docdiesel's Avatar
Moderator
 
Join Date: Aug 2007
Location: Munich
Posts: 289
#9: Dec 1 '07

re: %USERPROFILE% - What is this?


Hi,

Quote:

Originally Posted by Perl Beginner

What is %USERPROFILE%? And why is it showing up???

as you guessed, %USERPROFILE% is a windows environment variable. It points to your windows settings and documents folder, usually paced under c:\docs and settings\username . What windows version are you working with? Is it Vista? I'm not sure, but afaik Vi$ta is working with some special and sometimes hidden entries in the home filesystem. This could be one of it.

Regards,

Bernd
Reply