cwd

Python - How do I write a decorator that restores the cwd?

How do I write a decorator that restores the current working directory to what it was before the decorated function was called? In other words, if I use the decorator on a function that does an os.chdir(), the cwd will not be changed after the function is called. ...

Perl getcwd ending forward slashes

I am doing a Perl script to attach another variable to the end of the current working directory, but I am having problems with using the module. 1. If I run getcwd from D:\, the value returned is D:/ (with forward slash) If I run getcwd from D:\Temp\, the value returned is D:/temp (without forward slash) This makes the situation quite ...

Accessing files in the same directory as script

I need to access files that are relative to the location of my Ruby script. The only solution I've found is using File.dirname(__FILE__), however, if the script is run from a symlink, __FILE__ gives the location of the symlink. I would prefer a solution that does not involve looking at __FILE__, checking if it's a link, if it is, findi...

What's that best way to move through directories?

Are both of the examples below OK, or is the second one bad style? Case 1: Stay in top directory and use catdir to access subdirectories #!/usr/bin/env perl use warnings; use strict; my $dir = 'my_dir_with_subdir'; my ( $count, $dh ); use File::Spec::Functions; $count = 0; opendir $dh, $dir or die $!; while ( defined( my $file = re...

Client-Side VBScript application, Incorrect Current Working Directory

I'm not understanding this behavior. Maybe someone can explain to me why my current working directory is not what I expect. On my desktop, I have a folder called STKGui: C:\Documents and Settings\Lauren\Desktop\STKGui Located in that directory are the following files: gui.html, style.css, save.html, load.html Within STKGui there are ...

Is there a hook in Bash to find out when the cwd changes?

I am usually using zsh, which provides the chpwd() hook. That is: If the cwd is changed by the cd builtin, zsh automatically calls the method chpwd() if it exists. This allows to set up variables and aliases which depend on the cwd. Now I want to port this bit of my .zshrc to bash, but found that chpwd() is not recognized by bash. Is a ...

Bash script: set current working directory to the directory of the script

I'm writing a bash script (extremely unpleasant experience, as always) and I need the current working directory to act sanely. When I run the script from the directory in which it is in, it's fine. However, when I run it from somewhere else, the current working directory is for some reason propagated to the script. This is obviously u...

CWD of an Node.js application started with upstart (Ubuntu)

I've coded an node.js app that when get executed need to return CWD from process to be able to read files on disk. When I start the app directly with node in the actual app directory... #!sh node app.js everything is working fine and "process.cwd()" return the good path. But when the script is started with upstart or even direct...