Difference Between getcwd() and dirname(__FILE__) ? Which should I use?

__FILE__ is a magic constant containing the full path to the file you are executing. If you are inside an include, its path will be the contents of __FILE__. So with this setup: /folder/random/foo.php <?php echo getcwd() . “\n”; echo dirname(__FILE__) . “\n” ; echo “——-\n”; include ‘bar/bar.php’; /folder/random/bar/bar.php <?php echo getcwd() . “\n”; echo … Read more

Iterate through folders, then subfolders and print filenames with path to text file

Charles’ answer is good, but can be improved upon to increase speed and efficiency. Each item produced by os.walk() (See docs) is a tuple of three items. Those items are: The working directory A list of strings naming any sub-directories present in the working directory A list of files present in the working directory Knowing … Read more

How to make g++ search for header files in a specific directory?

A/code.cpp #include <B/file.hpp> A/a/code2.cpp #include <B/file.hpp> Compile using: g++ -I /your/source/root /your/source/root/A/code.cpp g++ -I /your/source/root /your/source/root/A/a/code2.cpp Edit: You can use environment variables to change the path g++ looks for header files. From man page: Some additional environments variables affect the behavior of the preprocessor. CPATH C_INCLUDE_PATH CPLUS_INCLUDE_PATH OBJC_INCLUDE_PATH Each variable’s value is a list of … Read more