Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6745519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:12:54+00:00 2026-05-26T12:12:54+00:00

Is it possible to use perl’s move function from File::Copy module to use a

  • 0

Is it possible to use perl’s move function from File::Copy module to use a wildcard to move a number of common files with the same file extension?
So far, I can only get move to work if I explicitly name the files.

For example, I wanted to do something like so:

my $old_loc = "/share/cust/abc/*.dat";
my $arc_dir = "/share/archive_dir/";

Right now, I can do one file like so:

use strict;
use warnings;
use File::Copy;

my $old_loc = "/share/cust/abc/Mail_2011-10-17.dat";
my $arc_dir = "/share/archive_dir/Mail_2011-10-17.dat";
my $new_loc = $arc_dir;

#archive
print "Moving files to archive...\n";
move ($old_loc, $new_loc) || die "cound not move $old_loc to $new_loc: $!\n";

What I want to do at the end of my perl program, move all these files named *.dat to an archive directory.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T12:12:55+00:00Added an answer on May 26, 2026 at 12:12 pm

    You can use Perl’s glob operator to get the list of files you need to open:

    use strict;
    use warnings;
    use File::Copy;
    
    my @old_files = glob "/share/cust/abc/*.dat";
    my $arc_dir = "/share/archive_dir/";
    
    foreach my $old_file (@old_files)
    {
        my ($short_file_name) = $old_file =~ m~/(.*?\.dat)$~;
        my $new_file = $arc_dir . $short_file_name;
    
        move($old_file, $new_file) or die "Could not move $old_file to $new_file: $!\n";
    }
    

    This has the benefit of not relying on a system call, which is unportable, system-dependent, and possibly dangerous.


    EDIT: A better way to do this is just to supply the new directory instead of the full new filename. (Sorry for not thinking of this earlier!)

        move($old_file, $arc_dir) or die "Could not move $old_file to $new_file: $!\n";
        # Probably a good idea to make sure $arc_dir ends with a '/' character, just in case
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: In Perl, how can I check from which module a given function
Is it possible to use a Perl hash in a manner that has O(log(n))
I'm trying to a good Perl module to use for connecting to a Sybase
Is it possible to run an external process from Perl, capture its stderr, stdout
Is possible to use different version of Perl without using the SET or manipulating
Possible Duplicate: Which version of Perl should I use on Windows? I want to
I am wondering if it is possible to use a single perl cgi script
Seem like my daily road block. Is this possible? String in qw? #!/usr/bin/perl use
I'm writing a script in Perl that reads from a file and prints the
Is it possible to use a single line foreach loop in Perl? $hash{$thing}++ foreach

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.