Software, your way.
burger menu icon
WillMaster

WillMaster > LibrarySnooping (Information Retrieval)

FREE! Coding tips, tricks, and treasures.

Possibilities weekly ezine

Get the weekly email website developers read:

 

Your email address

name@example.com
YES! Send Possibilities every week!

Finding the Current Working Directory

The current working directory when applied to CGI programs is:

  1. The default directory where the program will look for files when no directory path was specified with the file name.
  2. The base directory the program will assume when relative directory paths are specified.

For Unix/Linux servers, the current working directory usually is the directory where the CGI program is installed and running in.

But it's not always the case. Servers can be configured in a multitude of different ways.

When a CGI script doesn't find a file you know is where you specified it to be, it may be that the current working directory is not what you think it is.

The following short script can determine the current working directory for you.

(Master Pre-Installation Tester can be used instead if you prefer not to create your own testing script.)

#!/usr/bin/perl
use strict;
use Cwd;

my $dir = getcwd;

print "Content-type: text/html\n\n";
print "

Current working directory is:
$dir

"; opendir D,'.'; my $d = join '
',readdir D; print '

Listing of current working directory is:
',$d,'

';

Install the above script where CGI scripts can run (e.g. the cgi-bin). If testing for the current working directory that another script is using, install the above in the same directory as the other script.

Use a plain text word processor like NotePad or TextWrangler when copying the above script and saving it to a file. Use an FTP program to upload the file to your server, uploading it as a plain text file, not as a binary file. Then give the uploaded file 755 permissions.

Type the URL of the script into your browser to obtain the current working directory.

Will Bontrager

Was this article helpful to you?
(anonymous form)

Support This Website

Some of our support is from people like you who see the value of all that's offered for FREE at this website.

"Yes, let me contribute."

Amount (USD):

Tap to Choose
Contribution
Method

All information in WillMaster Library articles is presented AS-IS.

We only suggest and recommend what we believe is of value. As remuneration for the time and research involved to provide quality links, we generally use affiliate links when we can. Whenever we link to something not our own, you should assume they are affiliate links or that we benefit in some way.

How Can We Help You? balloons
How Can We Help You?
bullet Custom Programming
bullet Ready-Made Software
bullet Technical Support
bullet Possibilities Newsletter
bullet Website "How-To" Info
bullet Useful Information List

© 1998-2001 William and Mari Bontrager
© 2001-2011 Bontrager Connection, LLC
© 2011-2024 Will Bontrager Software LLC