in reply to Re^6: File::Find problems
in thread File::Find problems

<STDIN> doesn't read from the command line. The command line isn't even a stream. The command line is placed in @ARGV. If you're getting it via STDIN, typing
$ foo.pl /Users/me/Pictures/a b c d
is fine. If you're passing it via the command line, you'll need to convert the string into something a string literal your shell will interpret as the appropriate string. For bash, you can use
$ foo.pl /Users/me/Pictures/a\ b\ c\ d $ foo.pl '/Users/me/Pictures/a b c d' # Use '\'' for single quotes $ foo.pl "/Users/me/Pictures/a b c d" # Will interpolate like Perl

Replies are listed 'Best First'.
Re^8: File::Find problems
by 7stud (Deacon) on Jan 15, 2010 at 08:48 UTC

    Sorry, I meant STDIN when I said the command line.

    Here is my new error:

    Cross-device link at 2perl.pl line 29

    Here is line 29:

    rename $_, $new_path or die "$!";

      Directories are lists of associations between names and files. Renaming a file just changes the directories. The file itself is untouched.

      Since directories in one partition/disk/system can't refer to files in another, you can't rename files from one partition/disk/system to another.

      To copy a file then delete the original, you can use File::Copy's move

        Thanks for hanging in there with me.

        I used File::Copy's move(), and that seemed to work. But it moved all of the files except two. All the files I want to move are in one directory and have a .NEF extension. They are mixed in with other files having a .JPG or .AVI extension.

        I had my script print out the name of each file before moving it. Here is part of the output:

        DSC_0102.NEF DSC_0098.NEF DSC_0103.NEF DSC_0104.NEF DSC_0101.NEF Couldn't move DSC_0101.NEF: Operation not permitted at 2perl.pl line 3 +0 ... ... DSC_0135.NEF DSC_0136.NEF Couldn't move DSC_0136.NEF: Operation not permitted at 2perl.pl line 3 +0. DSC_0137.NEF ... ...

        Here is my code:

        use strict; use warnings; use 5.010; use File::Find; use File::Copy; my $destination_dir = "/Users/me/Pictures/a b c d"; my $volume_name = "/Volumes/Volume\\ Name"; #need double slash in path for glob() in next line #(see glob docs) for (glob "$volume_name/*") { if (-d) { find(\&wanted, $_); } } sub wanted { if (-f && /\.NEF$/) { my $new_path = "$destination_dir/$_"; say $_; move $_, $new_path or warn "Couldn't move $_: $!"; #**LINE 30 +*** } }