http://www.perlmonks.org?node_id=11128802


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

Start simple:
I may be wrong, but I think your regex is wrong.
'+' is not a valid file name character.
Start by printing the proposed files to be moved:
I don't know what \+ means?
#!/usr/bin/perl use strict; use warnings; use File::Copy; my ($inDir, $outDir) = @ARGV; opendir (DIR, $inDir) or die "Bad Input Directory $inDir $!\n"; while (my $infile = readdir(DIR)) { if ($infile =~ 'F\d{8}\.\d{4}\+\d{4}\-\d{4}\+\d{4}_.*') #like F12345678.1234+1234-9876+3456..... { print "$inDir/$infile\n"; } }

Replies are listed 'Best First'.
Re^2: Move a file to another directory based on regex match
by parv (Vicar) on Feb 26, 2021 at 01:53 UTC
Re^2: Move a file to another directory based on regex match
by Anonymous Monk on Feb 25, 2021 at 22:23 UTC
    '+' is not a valid file name character.

    yes it is. read the thread. this isnt windows.

      No issue on Windows 10 either in Windows Powershell with vim x+v.

Re^2: Move a file to another directory based on regex match
by DAN0207 (Acolyte) on Feb 26, 2021 at 17:02 UTC

    Thanks a ton!! It worked. I was missing on many other things which i cleared from your suggestions.