Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Move a file to another directory based on regex match

by haukex (Bishop)
on Feb 25, 2021 at 14:57 UTC ( #11128784=note: print w/replies, xml ) Need Help??


in reply to Move a file to another directory based on regex match

The error message is strange, but I do see one issue with your code: readdir returns just the filenames without the directory name. I'd recommend you use File::Spec::Functions qw/catfile/; and move( catfile($InDir,$Infile), $OutDir ). If that fixes the issue, then perhaps the error message is just wrong (is this Windows or some OS other than *NIX?), and if it's doesn't fix the issue, please let us know Update: along with more information about $InDir and $OutDir. Also, Use strict and warnings!

Replies are listed 'Best First'.
Re^2: Move a file to another directory based on regex match
by Corion (Pope) on Feb 25, 2021 at 15:16 UTC

    In fact, the documentation about readdir mentions the fact that you need to prepend the directory again.

    Just in the (very unlikely) case that the files actually exist, the error message suggests that the OP is trying to move them across mount points. This would happen for example if you have two disks mounted below /mount:

    /mount/hda/dir1 /mount/hdb/dir2

    Then, moving files from /mount/hda/dir1 to /mount/hdb/dir2 would mean actually copying the bytes between the two devices. At least the mv program (and thus, maybe also the rename() syscall?) on my Debian system does such copying nowadays...

      actually copying the bytes between the two devices. At least the mv program (and thus, maybe also the rename() syscall?) on my Debian system does such copying nowadays...

      It's a good thing OP is using File::Copy, since that actually does copy the bytes (and only when necessary, AFAIK) - I belive this is what the OS's mv does too. I just tried rename across filesystems and did in fact get the Invalid cross-device link error.

      So maybe the detection of the sameness of the device doesn't work correctly in MSWin?

      map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
Re^2: Move a file to another directory based on regex match
by DAN0207 (Acolyte) on Feb 25, 2021 at 16:58 UTC

    Thank you. I tried as per your kind suggestion , but didnt work. My $InDir value is /spool/input/parse and $OutDir is /spool/input/parsed

      Thank you. I tried as per your kind suggestion , but didnt work. My $InDir value is /spool/input/parse and $OutDir is /spool/input/parsed

      Still a bit strange. Could you please try the following things / give us the following information?

      • Try picking a fixed pair of paths and see if perl -wMstrict -MFile::Copy -e 'move("/spool/input/parse/FILENAME","/spool/input/parsed") or die $!' produces the same error
      • Show the output of perl -V
      • Show the output of perl -MFile::Copy -le 'print $File::Copy::VERSION'
      • Show the output of ls -ld /spool /spool/input /spool/input/parse*
      • Show the output of mount | grep spool
      • Let us know how you're running this script, e.g. from the command line, from cron, from a webserver, from some other script or a batch file, some other job scheduler, etc.?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11128784]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2021-05-13 01:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Perl 7 will be out ...





    Results (134 votes). Check out past polls.

    Notices?