Thread: what must be syntax?

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    83

    what must be syntax?

    dear all,
    I am trying to open the directory called tmp..but it showing

    No file or Directory found...

    how i should give directoy name? weather i need to give path? only name is safficient?Thanks in advance



    Code:
    my $dir = '/tmp';
    
        opendir(DIR, $dir) or die $!;

  2. #2
    Banned
    Join Date
    Nov 2007
    Posts
    678
    Dang!
    Have you ever used the Linux terminal?
    Use the same conventions for path naming

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    83

    thanks for your responce

    Quote Originally Posted by manav View Post
    Dang!
    Have you ever used the Linux terminal?
    Use the same conventions for path naming
    i havn't used LINUX Terminal? please can suggest the syntax?

  4. #4
    Cogito Ergo Sum
    Join Date
    Mar 2007
    Location
    Sydney, Australia
    Posts
    463
    What exactly are you trying to do lol.

    It should be something like cd <folder>
    =========================================
    Everytime you segfault, you murder some part of the world

  5. #5
    Registered User
    Join Date
    Apr 2008
    Posts
    32
    try this

    Code:
    #!/usr/bin/perl -w
    
    $dirname = "/tmp";
    
    opendir ( DIR, $dirname ) || die "Error in opening dir $dirname\n";
    while( ($filename = readdir(DIR)))
    {
         print("$filename\n");
    }
    closedir(DIR);

  6. #6
    Registered User
    Join Date
    Apr 2008
    Posts
    32
    which platform are you writing this for? Windows, Mac, Solaris, AIX, HP-UX, Linux?
    Are you sure you have a tmp directory?

  7. #7
    Registered User
    Join Date
    Apr 2008
    Posts
    83
    Quote Originally Posted by sillyman View Post
    try this

    Code:
    #!/usr/bin/perl -w
    
    $dirname = "/tmp";
    
    opendir ( DIR, $dirname ) || die "Error in opening dir $dirname\n";
    while( ($filename = readdir(DIR)))
    {
         print("$filename\n");
    }
    closedir(DIR);
    Here is complete code i am using:-
    Error:- No such file or directory

    Dir:-CUBAS_ComStack_COMMON(placed in same directory as script)

    Code:
    #!/usr/bin/perl
    
        use strict;
        use warnings;
    
        my $dir = '/CUBAS_ComStack_COMMON';
    
        opendir(DIR, $dir) or die $!;
    
        while (my $file = readdir(DIR)) {
    
            # Use a regular expression to ignore files beginning with a period
            next if ($file =~ m/^\./);
    
    	print "$file\n";
    
        }
    
        closedir(DIR);
        exit 0;

  8. #8
    Banned
    Join Date
    Nov 2007
    Posts
    678
    Try removing the '/' from the dir name!

  9. #9
    Registered User
    Join Date
    Apr 2008
    Posts
    32
    Your code is correct. Check the perms on the directory.

  10. #10
    Registered User
    Join Date
    Apr 2008
    Posts
    32
    or try ./ are you sure that is right path name?

  11. #11
    Registered User
    Join Date
    Apr 2008
    Posts
    83

    THanks very much i got it?

    Quote Originally Posted by sillyman View Post
    or try ./ are you sure that is right path name?
    But it listing only one level..it consists of subdirectories also i want list files from subdirectories also..what must be logic?

  12. #12
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Okay... this really has nothing to do with C. You probably want `ls -R /tmp` (for recursive) or `tree /tmp`. Both can be found in the manual.

  13. #13
    Registered User
    Join Date
    Apr 2008
    Posts
    32
    true, about the c part, but for perl look up function

    finddepth

    are you trying to create the Unix find command?

    for c programming try ftw function.

  14. #14
    Banned
    Join Date
    Nov 2007
    Posts
    678
    yeah right zacs!
    at least move to general discussions.

    but this can surely be done using C:
    Code:
    char cmd[512];
    sprintf(cmd, "ls -R &#37;s", dirName);
    system(cmd);
    Edit: I forgot to add my dreaded laugh!
    MuwahahahahahhaHaHahahaahhaaahahahahha

  15. #15
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Har har, you funny man

    If you wanted to do it in C, opendir/readdir() would be your best bet. Rather trivial if you ask me

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. more then 100errors in header
    By hallo007 in forum Windows Programming
    Replies: 20
    Last Post: 05-13-2007, 08:26 AM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 07:33 AM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM