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 6927523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:03:59+00:00 2026-05-27T11:03:59+00:00

I am using File::Find and file i/o on a text file to parse a

  • 0

I am using File::Find and file i/o on a text file to parse a series of directories and move the contents into a new folder. It is a simple script (see below):

#!/usr/bin/perl

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

my $dir = "/opt/CollectMinderDocuments/coastalalglive"; #base directory for Coastal documents

#read file that contains a list of closed IDs
open(MYDATA, "Closed.txt");

mkdir("Closed");

while(my $line = <MYDATA>) {
  chomp $line;
  my $str = "$dir" . "/Account$line";
  print "$str\n";
  find(\&move_documents, $str);
}
sub move_documents {
  my $smallStr = substr $File::Find::name, 43;
  if(-d) {
    #system("mkdir ~/Desktop/Closed/$smallStr");
    print "I'm here\n";
    system("mkdir /opt/CollectMinderDocuments/coastalalglive/Closed/$smallStr");
    #print "Made a directory: /opt/CollectMinderDocuments/coastalalglive/Closed/$smallStr\n";
  }
  else {
    print "Now I'm here\n";
    my $smallerStr = substr $File::Find::dir, 43;
    my $temp = "mv * /opt/CollectMinderDocuments/coastalalglive/Closed/$smallerStr/";
    system("$temp");
  }
}

The text file contains a list of numbers:

1234
2805
5467

The code worked when I executed it last month, but it is now returning a “file or directory not found” error. The actual error is “No such file or directoryerDocuments/coastalalglive/Account2805”. I know all of the directories it is searching for exist. I have manually typed in one of the directories, and the script executes fine:

find(\&move_documents, "/opt/CollectMinderDocuments/coastalalglive/Account2805/");

I am not sure why the error is being returned. Thanks in advance for the help.

  • 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-27T11:04:00+00:00Added an answer on May 27, 2026 at 11:04 am

    Your error:

    "No such file or directoryerDocuments/coastalalglive/Account2805"
    

    Seems to imply that there is an \r that was not removed by your chomp. That will happen when transferring files between different file systems, where the file contains \r\n as line endings. The real error string would be something like:

    /opt/CollectMinderDocuments/coastalalglive/Account2805\r: No such file or directory
    

    Try changing chomp $line to $line =~ s/[\r\n]+$//; instead, and see if that works.

    Also:

    my $temp = "mv * /opt/CollectMinderDocuments/coastalalglive/Closed/$smallerStr/";
    system("$temp");
    

    Is very wrong. The first non-directory file in that loop will move all the remaining files (including dirs? not sure if mv does that by default). Hence, subsequent iterations of the subroutine will find nothing to move, also causing a “Not found” type error. Though not one caught by perl, since you are using system instead of File::Copy::move. E.g.:

    move $_, "/opt/CollectMinderDocuments/coastalalglive/Closed/$smallerStr/" or die $!;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a Perl script (in Windows) that is using File::Find to index
I'm trying to parse a text file into sentences ending in periods, but names
I want to create a very simple spell checker using a text file with
I am getting an error I do not understand. I am using File:Find to
I'm using the File::Find module to traverse a directory tree. Once I find a
How can I find extended ASCII characters in a file using Perl? Can anyone
I've been trying to find a way to write to a file when using
How to get the file names inside a directory using PHP? I couldn't find
I'm using file_get_contents('mysourcefile.html') to load the contents of mysourcefile.html into mysql db. I have
I am new to jquery. I am trying to parse xml string using jquery.

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.