Re: chdir not working
by GrandFather (Saint) on Mar 14, 2011 at 21:26 UTC
|
The code you have given is not Perl. // is not a valid Perl comment. Have you adapted this code from a different language perhaps? How about you show us some real code you have run and that demonstrates the problem you are having. Mean time, the following may be the Perlish version of what you are trying to do:
use strict;
use warnings;
use Cwd;
print cwd();
my $path_data = cwd () . "\\data"; #Also want to make the concat in-ca
+sesensitive
chdir($path_data) or die "Cant chdir to $path_data $!";
print "\n", cwd();
True laziness is hard work
| [reply] [d/l] |
Re: chdir not working
by toolic (Bishop) on Mar 14, 2011 at 21:22 UTC
|
The directory probably is changing, but you are printing a stale value. You did not change the value of the $cwd scalar variable between print's. If you are using Cwd, try this:
print "CWD:$cwd";
my $path_data = $cwd."\\data";//Also want to make the concat in-casese
+nsitive
chdir($path_data) or die "Cant chdir to $path_data $!";
$cwd = getcwd();
print "\nCWD:$cwd"; #//same directory as above gets printed
| [reply] [d/l] [select] |
|
|
Actually I want to go one level back and then append data like below,but seems like the syntax is not right,it nots going one level up.Can you advise how can I do that?
Cant chdir to E:/qdepot_automation/files\\data No such file or directory at perl.pl line 157
print "CWD:$cwd";
my $path_data = $cwd."..\\\\data";//Also want to make the concat in-ca
+sese
+nsitive
chdir($path_data) or die "Cant chdir to $path_data $!";
$cwd = getcwd();
print "\nCWD:$cwd"; #//same directory as above gets printed
| [reply] [d/l] |
Re: chdir not working
by ikegami (Patriarch) on Mar 14, 2011 at 21:54 UTC
|
btw, if $cwd contains the current work directory,
my $path_data = $cwd."\\data";
chdir($path_data)
is the same as
my $path_data = "data";
chdir($path_data)
| [reply] [d/l] [select] |
|
|
| [reply] |
|
|
c:\>cd @wOrK\PeRl
c:\@Work\Perl>
c:\@Work\Perl>dir uPD*
Volume in drive C is Acer
Volume Serial Number is 1234-5678
Directory of c:\@Work\Perl
02/13/2010 07:57 PM 4,098 Updfxgen.pl
02/13/2010 07:57 PM 3,956 Updfxgen.pl1
02/13/2010 07:57 PM 33,199 updgen.pl
02/13/2010 07:57 PM 1,732 Updungen.pl
02/13/2010 07:57 PM 1,589 Updungen.pl1
5 File(s) 44,574 bytes
0 Dir(s) 256,281,104,384 bytes free
Update: Expanded the example. Also: Perl commands for the Windows API (not for the command line!) accept a / (forward slash) just as well as a \ (backslash), alleviating the need to escape backslashes in double-quoted strings.
| [reply] [d/l] |
|
|
If the file system is case-insensitive, then chdir('data'), chdir('Data'), chdir('DATA'), etc will all switch to your data directory, however it was named at creation.
If the file system is case-sensitive, then only one of chdir('data'), chdir('Data'), chdir('DATA'), etc will switch to your data directory.
| [reply] |
|
|
This is not working for me,am using 5.6.1,does that make a difference?
On a side note,how do I update my previous replies
| [reply] |
|
|
| [reply] |
|
|
You need to have been logged in when you made the post. Otherwise, anyone would be able to update any anonymous post.
| [reply] |
|
|
| [reply] |
|
|
What do you mean by not working? I didn't say either would work; I said they were the same. Do you mean they're not the same for you? If so, why do you think they are different?
| [reply] |
|
|
| [reply] |