Gossamer Forum
Home : Products : Gossamer Forum : Discussion :

if folder exists...

Quote Reply
if folder exists...
I'm trying to create a global that will check to see if a folder, named the same as a user's login name, exists under /www/html/files/{user_name}. It then needs to return a link if it does, and a different link if it doesn't. So basically it would be:

<%my_global(user_name)%>

Then, the global would take the current user name passed to it, and check to see if the folder exists. It would then return the appropriate href line.

I hope I made some sort of sense with this. Any help would be greatly appreciated. I'm not that great of a programmer. Unsure

Sean
Quote Reply
Re: [SeanP] if folder exists... In reply to
Try this;

1) Make a new global; call it "check_folder_exists", and put the following code in;

Code:
sub {

my $folder = '/full/path/to/folder';
my $user = $_[0];

if (-e "$folder/$user") {
return { folder_exists_user => 1 };
} else {
return { folder_exists_user => 0 };
}
}

2) Then open the template, and put;

Code:
<%check_folder_exists($Username)%>

... which will then set <%folder_exists_user%> to either 1 or 0, depending if the folder exists.

3) You can check this with;

Code:
<%if folder_exists_user %>
... folder exists
<%else%>
do something else
<%endif%>

This is untested, and $Username may need to be replace for the specific user. However, the format should be ok Smile

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] if folder exists... In reply to
Wow, thanks, Andy! If I pass the username from the template, is that the correct syntax? I'm not sure if the following will work:

<%check_folder_exists(current_user_username)%>

The tag for the current user is:
<%current_user_username%>

Thanks,
Sean
Quote Reply
Re: [SeanP] if folder exists... In reply to
No worries. In that case, you need to use;

<%check_folder_exists($current_user_username)%>

Note the additional $, which is required to pass tags into globals.

Should work though :)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] if folder exists... In reply to
Thanks, Andy! It works great!

Sean