News : The level of daily SPAM has reached insane proportions, all registrations are now manual. I ask you to send me an e-mail (john (at) murga (dot) org), to confirm that you want me to create an account for you.


Post Reply  Post Thread 
Function to return the current directory
Author Message
mikshaw
Senior Member
****


Posts: 522
Group: Registered
Joined: Apr 2007
Status: Offline
Reputation: 5
Post: #1
RE: Function to return the current directory

Here's one possible solution. It works in Unix systems, but I think a forward slash will not translate to Windows. The gsub function will probably need to be modified or replaced for something more universal, but the main point is that arg[0] stores the full path to the script.

Code:
dirname=string.gsub(arg[0],"(%/.*)%/.*","%1")
print(dirname)


EDIT:
Again, this is probably not the cleanest or most useable code, but it might work...

Code:
function dirname(f)
if not f then f=arg[0] end
local s
if murgaLua.getHostOsName() == "windows" then s="\\" else s="/" end
local dirname=string.gsub(f,"(.*"..s..").*","%1")
return(dirname)
end


The function was designed so that it would work on the current script if no arguments are given, and can also be used on other files similar to the dirname command in linux (except this one keeps the trailing slash)

This post was last modified: 07-16-2007 04:00 AM by mikshaw.

07-16-2007 03:29 AM
Find all posts by this user Quote this message in a reply
Post Reply  Post Thread 

Messages In This Thread
RE: Function to return the current directory - mikshaw - 07-16-2007 03:29 AM

View a Printable Version
Send this Thread to a Friend
Subscribe to this Thread | Add Thread to Favorites

Forum Jump: