473,503 Members | 2,197 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using pwd and chdir to move back to previous directory

2 New Member
I am in unix and in my perl program, I am trying to move back to the directory the program was originally started in. Obviously, at somepoint in my program it has to move to another directory, and now I want to go back.
I tried this lines of perl at the start of the program:
$directorylocation=`pwd`;

and then this command later on when it is time to move back:

chdir $directorylocation;

and it doesn't work. I have checked that $directorylocation does have the correct path and dir. And when I type in the path and directory like this
chdir "g/g14/rdoneil/test";
this line will work. But I can't get the variable to do the job.
(I have also tried
chdir "$directorylocation"; but no-go)

By the way, another option is just moving up two directories - as that is where the program originally started out. But I am thinking there is no easy way to accomplish this.
Sep 26 '07 #1
4 10762
KevinADC
4,059 Recognized Expert Specialist
try this:

chdir ($directorylocation) or die "can't chdir to $directorylocation: $!";

and see if you get an error message.
Sep 27 '07 #2
eWish
971 Recognized Expert Contributor
Can you show us more code. The code that shows where and how $directorylocation is defined. As well as where it is being used with chdir .

Edit: Man, I was to slow.
Sep 27 '07 #3
mehj123
55 New Member
I think the problem is that perl's chdir() function is global.. This means that once you use the chdir() function, it changes the directory for the whole program.. I found that File::chdir module can be used to get a solution to this problem. dont know much.. :)
Sep 27 '07 #4
rdoneil
2 New Member
I am in unix and in my perl program, I am trying to move back to the directory the program was originally started in. Obviously, at somepoint in my program it has to move to another directory, and now I want to go back.
I tried this lines of perl at the start of the program:
$directorylocation=`pwd`;

and then this command later on when it is time to move back:

chdir $directorylocation;

and it doesn't work. I have checked that $directorylocation does have the correct path and dir. And when I type in the path and directory like this
chdir "g/g14/rdoneil/test";
this line will work. But I can't get the variable to do the job.
(I have also tried
chdir "$directorylocation"; but no-go)

By the way, another option is just moving up two directories - as that is where the program originally started out. But I am thinking there is no easy way to accomplish this.

I solved it!

Instead of just doing this:

$directorylocation=`pwd`;

I now add this line:

chomp($directorylocation);

And it now works just fine!
Sep 27 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
16743
by: John | last post by:
Sorry, but how does one move up a directory ? I'm in a directory from which I called a script. Part of the script functionality is checking the permissions of the directory I am in. I may need...
0
1245
by: jeffgeorge | last post by:
I'm trying to accomodate users who are requesting a "back" button ala an internet browser. It will be primarily used to peel off layers of a filter by selection but I'm sure it will inevitably be...
8
2087
by: moondaddy | last post by:
Is there a way to make the browser move back to the previous page via code behind on the server? The effect would be the same as the user clicking on the browser's back button. Thanks. --...
1
1448
by: I2 | last post by:
I am new to .net and am stumped as to how to use "include" files in my asp application. Currently I have created classes in the app_code directory that are shared between various aspx pages and...
2
1677
by: Dabulsta | last post by:
I am trying to design a network using Windows Server 2003 Active Directory infrastructure for the following company(below) and I was wondering if there was some sort of walk through available to...
2
2201
by: Sofia Zarin | last post by:
Hello every one. Can someone help me regarding how to move to previous record and next record through hyper links. One can have the example of the below mentioned block: << 1 2 3 4 5 6 ..........
4
2088
by: widevision7 | last post by:
I have a script where I am using glob to get a list of folders that end in "*import", but I am trying to change my directory to the previous one. Here is what I have: @directories =...
3
1826
by: =?Utf-8?B?UHVyZSBIZWFydA==?= | last post by:
hi i need the code to move files from directory to another directory on sam local machine or to a network path, thank you. -- Ammar S. Mitoori IT Head QIMCO Co. Tel : +9744831199 Mobile :...
1
1347
by: yash777 | last post by:
actually, i updated database with pop up window and after updation i have to move back to the parent window. i solved the first question by closing the popup window. but how refresh the...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7349
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7008
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7467
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5594
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5022
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3168
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1521
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
399
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.