Home > Archive > PERL Beginners > July 2005 > chdir and mkdir
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| Jan Eden 2005-07-26, 4:05 am |
| Hi,
this does not work:
mkdir "/some/dir/newsubdir" or die "$!";
while this does:
chdir "/some/dir";
mkdir "newsubdir/" or die "$!";
In the shell, I can obviously execute the former.
Is it true that in Perl, I can create a directory only within the current w=
orking directory?
Thanks,
Jan
--=20
These are my principles and if you don't like them... well, I have others. =
- Groucho Marx
| |
| Jan Eden 2005-07-26, 4:05 am |
| Jan Eden wrote on 26.07.2005:
>Hi,
>
>this does not work:
>
>mkdir "/some/dir/newsubdir" or die "$!";
>
>while this does:
>
>chdir "/some/dir"; mkdir "newsubdir/" or die "$!";
>
>In the shell, I can obviously execute the former.
>
>Is it true that in Perl, I can create a directory only within the
>current working directory?
>
>Thanks,
>
>Jan -- These are my principles and if you don't like them... well, I
>have others. - Groucho Marx
>
Apologies: Just found File::Path.
Thanks,
Jan
--=20
Unix is user friendly - it's just picky about it's friends.
| |
| John W. Krahn 2005-07-26, 4:05 am |
| Jan Eden wrote:
> Hi,
Hello,
> this does not work:
>
> mkdir "/some/dir/newsubdir" or die "$!";
That works for me. What error message do you get?
Have you tried the mkpath() function from the File::Path module?
perldoc File::Path
John
--
use Perl;
program
fulfillment
| |
| Jan Eden 2005-07-26, 9:00 am |
| Hi John,
John W. Krahn wrote on 26.07.2005:
>Jan Eden wrote:
>
>Hello,
>
>
>That works for me. What error message do you get?
>
I get "File exists". /some/dir does exist, but newsubdir does not.
>Have you tried the mkpath() function from the File::Path module?
>
Yes, I checked that just seconds after posting (apologies). mkpath() works =
for me.
But I wonder why my initial example works for you. File::Path doc says:
'The "mkpath" function provides a convenient way to create directories, eve=
n if your "mkdir" kernel call won't create more than one level of directory=
at a time. '
But my system's mkdir does execute
mkdir /some/dir/newsubdir
while this does not work via Perl's mkdir function.
Anyway, I will use File::Path.
Thanks,
Jan
--=20
Life's unfair - but root password helps!
| |
| Xavier Noria 2005-07-26, 9:00 am |
| On Jul 26, 2005, at 11:31, Jan Eden wrote:
> But I wonder why my initial example works for you. File::Path doc
> says:
>
> 'The "mkpath" function provides a convenient way to create
> directories, even if your "mkdir" kernel call won't create more
> than one level of directory at a time. '
>
> But my system's mkdir does execute
>
> mkdir /some/dir/newsubdir
>
> while this does not work via Perl's mkdir function.
>
> Anyway, I will use File::Path.
OK, would you please show us a test copying a shell session that
demonstrates the issue? That is, open a terminal, do some "ls"s,
"mkdir"s, perl one-liners, etc. Something we can reproduce in a Unix
machine.
-- fxn
| |
| Jan Eden 2005-07-26, 9:00 am |
| Xavier Noria wrote on 26.07.2005:
>On Jul 26, 2005, at 11:31, Jan Eden wrote:
>
>OK, would you please show us a test copying a shell session that =20
>demonstrates the issue? That is, open a terminal, do some "ls"s, =20
>"mkdir"s, perl one-liners, etc. Something we can reproduce in a Unix =20
>machine.
Ahem. Very strange:
[jan:~/tmp] ls foo
bar
[jan:~/tmp] ls
foo
[jan:~/tmp] ls foo
bar
[jan:~/tmp] mkdir foo/bar/subdir
[jan:~/tmp] ls foo/bar/
subdir
[jan:~/tmp] rmdir foo/bar/subdir/
[jan:~/tmp] perl -e 'mkdir "foo/bar/subdir";'
[jan:~/tmp] ls foo/bar/
subdir
Now it works! I have no clue what went wrong, but I will investigate.
Thanks,
Jan
--=20
Lead me not into temptation. I can find it myself. - Jeffrey Kaplan
| |
| John W. Krahn 2005-07-26, 9:00 am |
| Jan Eden wrote:
>
> John W. Krahn wrote on 26.07.2005:
>
> I get "File exists". /some/dir does exist, but newsubdir does not.
The message "File exists" means that the file /some/dir/newsubdir
already exists when mkdir tried to create it.
John
--
use Perl;
program
fulfillment
| |
| Randal L. Schwartz 2005-07-26, 9:00 am |
| >>>>> "Jan" == Jan Eden <lists@janeden.org> writes:
Jan> chdir "/some/dir";
This might have failed...
Jan> mkdir "newsubdir/" or die "$!";
which would make this in the wrong directory. Are you checking that?
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
| |
| Jan Eden 2005-07-26, 9:00 am |
| Randal L. Schwartz wrote on 26.07.2005:
>The following message is a courtesy copy of an article
>that has been posted to perl.beginners as well.
>
>
>Jan> chdir "/some/dir";
>
>This might have failed...
>
>Jan> mkdir "newsubdir/" or die "$!";
>
>which would make this in the wrong directory. Are you checking that?
>
Yes, I am. I printed out the current working dir after executing chdir. I s=
eem to have made a stupid mistake at some point which I am unable to recons=
truct. Sorry for wasting everyone's time with this.
BTW, I have just rewritten a program to be completely OO with the help of L=
eaning Perl Objects, References and Modules. Great book.
Thanks,
Jan
--=20
Clothes make the man. Naked people have little or no influence on society. =
- Mark Twain
|
|
|
|
|