unlink full path to files

Ask a Question related to PERL Miscellaneous, Design and Development.

  1. #1

    Default Re: unlink full path to files

    Tony wrote at Thu, 03 Jul 2003 15:40:43 +0000:
    > I would like to use the full pathname with the unlink
    > function but it doesn't seem to work that way?
    > Is it possible or must you always be in the directory
    > that the files are deleted from?
    >
    > This is perl, v5.6.1 built for i386-linux
    >
    > use strict;
    > use warnings;
    >
    > These first two work,
    >
    > chdir '/floppy' or die "Can't cd to /floppy: $!\n";
    > system("rm /floppy/@delete_files") == 0 or warn
    > "Problem when system rm @delete_files: $!"; # works
    I doubt it.
    That will only work if @delete_files contains only 1 element.
    If @delete_files = ("a", "b") for example
    "rm /floppy/@delete_files" is interpolated to
    "rm /floppy/a b"
    what is perhaps something different of what you wanted to achieve.
    > chdir '/floppy' or die "Can't cd to /floppy: $!\n";
    > unlink @delete_files or warn
    That try to do something lik
    rm a b
    (with @delete_files like above)
    > "Problem when unlinking @delete_files: $!"; # works
    You might better try something like

    unlink map "/floppy/$_", @delete_files or die "...";


    Greetings,
    Janek
    Janek Schleicher Guest

  2. Similar Questions and Discussions

    1. Insert full path on browse file?
      Don't suppose you could post that code here? :)
    2. full path name
      I am a Windows programmer, so I got a very simple question regarding the full path name in Mac. I use MoreFiles library to convert a FSSpec to...
    3. Full path to the perl intrepter
      I'm in a very old project and my scripts are calling other scripts. I have 3 or 4 different perl version in the server. I need to call the...
    4. Full path to the perl interpreter
      the script are being called like /usr/local/bin/perl5.8.0/bin/perl -w /proj/xpto.pl I need the "/usr/local/bin/perl5.8.0/bin/perl" The usual...
    5. grabbing full path and file name
      Is there a method of setting up a button on a form and browsing available drives to get the full path and file name. The function would be...
  3. #2

    Default Re: unlink full path to files

    Tony <tony1911@hotmail.com> wrote:
    >
    > I would like to use the full pathname with the unlink
    > function

    That will be fine.

    > Is it possible

    Yes.

    > These don't work.
    >
    > chdir '/floppy' or die "Can't cd to /floppy: $!\n";
    > unlink "/floppy/@delete_files" or warn

    Try looking at what you are giving to unlink():

    print "/floppy/@delete_files";

    And you might see something like:

    /floppy/file1 file2 file3

    That is a single scalar, unlink wants a _list_.

    that should one file named '/floppy/file1 file2 file3',
    ie a filename with spaces in it.

    > "Problem when unlinking @delete_files: $!"; # error
    > No such file or directory at..

    What you _want_ unlink to see is the list of absolute paths:

    unlink '/floppy/file1', /floppy/file2', ...

    You could get that with (untested):

    unlink map { "/floppy/$_" } @delete_files;


    --
    Tad McClellan SGML consulting
    [email]tadmc@augustmail.com[/email] Perl programming
    Fort Worth, Texas
    Tad McClellan Guest

  4. #3

    Default Re: unlink full path to files

    Tony wrote:
    > I would like to use the full pathname with the unlink
    > function but it doesn't seem to work that way?
    Yes it does. You do not need to chdir to the directory where the files
    to be deleted are.
    > These don't work.
    >
    > chdir '/floppy' or die "Can't cd to /floppy: $!\n";
    > unlink "/floppy/@delete_files" or warn
    ---------^^^^^^^^^^^^^^^^^^^^^^^

    If the array @delete_files would include the elements 'file1.txt' and
    'file2.txt', that expression tries to do:

    unlink '/floppy/file1.txt file2.txt'

    which obviously cannot work.

    You can try to just do this (chmod not necessary):

    for (@delete_files) {
    unlink "/floppy/$_" or warn $!;
    }

    --
    Gunnar Hjalmarsson
    Email: [url]http://www.gunnar.cc/cgi-bin/contact.pl[/url]

    Gunnar Hjalmarsson Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139