Visit Our UNIX and Linux User Community


[Perl] Determine directory name


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Perl] Determine directory name
# 1  
Old 07-02-2009
[Perl] Determine directory name

Hi there,

I wonder if it is possible the determine a name of a directory which is different on various hosts.

Let me try to explain.

I have the directory /tmp/dir1/dir2/canchangedir.
This directory name is different on various hosts.
I need to use the directory name, independent from the host I am on.

This is the directory structure on all hosts (example):

/tmp/dir1
/tmp/dir1/dir2
/tmp/dir1/dir2/canchangedir
/tmp/dir1/dir2/canchangedir/dir3
/tmp/dir1/dir2/file1
/tmp/dir1/dir2/file2
/tmp/dir1/dir2/file3

The name "canchangedir" is different on all hosts.
The structure is the same and the dir1 and dir2 name too.

I tried with find and basename, but did not succeed.

Anyone out there that can do the magic ??

Thanks,

E.J.
# 2  
Old 07-02-2009
open the tmp directory and search it?
# 3  
Old 07-03-2009
Quote:
Originally Posted by KevinADC
open the tmp directory and search it?
@KevinADC,

Okay, a bit short (open it ? search it ? search what ?) , but I think I got it.

Code:
@dir2_contents = </tmp/dir1/dir2/*>;

foreach $item (@dir2_contents) {
  if ( -d $item ) {
    $needed_dir = basename($item);
  }
}

printf "needed_dir = $needed_dir\n";


Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Perl : Inline program to determine file size

Hi, I have 5 files as below $ ll sam* -rw-rw-rw- 1 sam ugroup 0 Mar 21 06:06 sam3 -rw-rw-rw- 1 sam ugroup 0 Apr 3 22:41 sam2 -rw-rw-rw- 1 sam ugroup 17335 Apr 10 06:07 sam1 -rw-rw-rw- 1 sam ugroup 5 Apr 10 07:53 sam5 -rw-rw-rw- 1 sam ugroup 661 Apr 10 08:16 sam4 I want to list out... (4 Replies)
Discussion started by: sam05121988
4 Replies

2. Shell Programming and Scripting

How to determine if there's a file in directory!

Hi All, I'm just wondering how can i determined if there's a file in directory and put it in a logs? dir="/home/test/" Please advise, Thanks, Use code tags, thanks. (1 Reply)
Discussion started by: nikki1200
1 Replies

3. Shell Programming and Scripting

Determine string in Perl.

Hi, I have a little Perl question. I need to determine the last word in the following string: h t t p://abc.def.com/hijklm The output should be the string hijklm. h t t p is of course http. The string between the slashes always differs. The string after the last slash always differs.... (4 Replies)
Discussion started by: ejdv
4 Replies

4. UNIX for Advanced & Expert Users

How Can I Easily Determine If A File Has been Added to a Directory

I am uploading files that need to be processed prior to uploading. I will put the files in a directory. My question is how can I write an easy process to kick off a script once a file has been added? Is there an easy way to determine if a file has been added to a directory? Thanks (7 Replies)
Discussion started by: goodmis
7 Replies

5. UNIX for Dummies Questions & Answers

How Can I Easily Determine If A File Has been Added to a Directory

I am uploading files that need to be processed prior to uploading. I will put the files in a directory. My question is how can I write an easy process to kick off a script once a file has been added? Is there an easy way to determine if a file has been added to a directory? Thanks (1 Reply)
Discussion started by: goodmis
1 Replies

6. UNIX for Advanced & Expert Users

cannot determine current directory

Hi, when I execute some simple commands on my solaris system, I am getting the following warning message: Could anybody tell me what could be the reason Ex:- If I give the command, which ls Warning: cannot determine current directory ... (15 Replies)
Discussion started by: axes
15 Replies

7. Shell Programming and Scripting

How to determine if a script (perl) was called from a CRON job or commandline

Hi, Is there a way to determine if a Script is called from a CRON job or from a commandline Gerry. (2 Replies)
Discussion started by: jerryMcguire
2 Replies

8. Shell Programming and Scripting

determine owner directory permissions from within the directory

From within a directory, how do I determine whether I have write permission for it. test -w pwd ; echo ? This doesn't work as it returns false, even though I have write permission. (4 Replies)
Discussion started by: Sniper Pixie
4 Replies

9. Shell Programming and Scripting

determine file type with perl

Hello i will like to know please how can i determine file type inside perl script not using the unix "file" program Thanks allot (1 Reply)
Discussion started by: umen
1 Replies

10. Shell Programming and Scripting

Perl Ping Determine Success or Fail

I know how to ping in Perl. That is easy. What I am wondering is if there is a way for Perl to determine whether the ping was successful or not. Or do I need to save the results out and parse the results seperately looking for the #of tries and successful revieves. Thanks. (1 Reply)
Discussion started by: gdboling
1 Replies

Featured Tech Videos