dirname

OS X bash: dirname

I want to create a simple bash script to launch a Java program on OS X. The names of the file, the file path, and the immediate working folder all contain spaces. When I do this: #!/bin/sh cd `dirname $0` I get usage: dirname path I have also tried putting quotes in all kinds of different places. The most elaborate example being c...

Finding a module's directory

How can I find what directory a module has been imported from, as it needs to load a data file which is in the same directory. edit: combining several answers: module_path = os.path.dirname(imp.find_module(self.__module__)[1]) got me what i wanted ...

shell script fun! how to perform an action on each subdirectory from a given path??

I am writing a shell script (which I suck at) and I need some help. Its a script that is moving things from git to CVS (not important). The thing is, i a file path: controllers/listbuilder/setup/SubmissionRolesListbuilderHandler.inc.php and I need to be able to do: cvs add controllers; cvs add controllers/listbuilder; cvs add cont...

How to properly determine current script directory in Python?

I would like to see what is best way to determine current script directory in python? I discovered that two to the many ways of calling python code, it is hard to find a good solution. Here are some problems: __file__ is not defined if the script is executed with exec, execfile __module__ is defined only in modules Use cases: ./...

Where does the dirname/basename terminology originate?

What are the origins and reasons for the terms, dirname and basename, referring to the path with the trailing component removed, and the trailing component respectively? Is the terminology standardized, and where? Are there alternative or equivalent conventions in use to refer to the splitting of a path in this way? Update0 In partic...

Unix C - Compiling for 64 bit breaks "dirname"

I'm using dirname from libgen.h to get the directory path from a filename's path. This is it's signature: char * dirname (char *path) When compiling on a 32 bit machine or using -m32 with gcc, it all works fine. My code looks like this: char* path = "/path/to/my/file.txt"; char* path_cpy = strdup(path); const char* dir = (const cha...