Recursion breaks While Loop

I am using a while loop to recurse through a set of folders and their subfolders - code is shown below.  The problem is that when it comes back from a recursion, it falls out of the while loop, even if there were more files in the parent folder that need to be moved, or other folders that should have been recursed into.  Any advice would be grand.

Here is the code.
.
.
.
#7: Move Working Logs to Minus 1
      print "Move Working Files\n";
      msgs_to_multi_logfiles ("Move Working Files", $h_message_msg, $strHostName);  #Call to pipereader to write log message.
      MoveFiles("${strWorkingLoc}/Logs/${strFolder}","${strArchiveLoc}/Logs/Minus1/${strFolder}");
.
.
.
sub MoveFiles
{
#This sub recursively moves all of the files and folders in a folder to a new folder
#Define variables for the parameters
      my ($strCurrentFolder,                  #The folder to search for files
            $strDestination                        #The folder to move the files to
            );
      
      my ($strFileName);
      
#Set the variables
      ($strCurrentFolder,$strDestination) = @_;
      print "MoveFiles called for Directory: $strCurrentFolder\n";
#1: Open Current Folder
      opendir(MOVEFILE,$strCurrentFolder);
      
      $strFileName = readdir MOVEFILE;
#2: Read file name, if . or .. ignore file
      do #while($strFileName = readdir MOVEFILE)
      {
            chomp $strFileName;
            print "strFileName to move is $strFileName\n";
            if (($strFileName eq ".") || ($strFileName eq ".."))
            {
                  print "File is . or .. -- skipping file\n";
            }
            else
            {
                  if (-d $strCurrentFolder . "/" . $strFileName)
                  #3: If file is a directory, create directory in destination, then recurse, appending
                  #      directory name to current folder and destination folder
                  {
                        print "Creating Subdirectory.\n";
                        mkdir("${strDestination}/${strFileName}");
                        MoveFiles("${strCurrentFolder}/${strFileName}/","${strDestination}/${strFileName}");
                        print "Back from recursed execution\n";
                  }
                  else
                  #4: If file is not a directory, move to destination folder
                  {
                        print "Moving File\n";
                        system("mv ${strCurrentFolder}/${strFileName} ${strDestination}");
                  }
            }
            print "Moving on with ${strCurrentFolder}.\n";
      } while($strFileName = readdir MOVEFILE);
      #5: No more files - close current folder, and exit sub
      closedir(MOVEFILE);
}


And here is a sample output:

Current Log Folder = Mobius
Move Working Files
MoveFiles called for Directory: //WFF999999SFS51A/Working/Logs/Mobius/
strFileName to move is .
File is . or .. -- skipping file
Moving on with //WFF999999SFS51A/Working/Logs/Mobius/.
strFileName to move is ..
File is . or .. -- skipping file
Moving on with //WFF999999SFS51A/Working/Logs/Mobius/.
strFileName to move is Copy5oftest.txt
Moving File
Moving on with //WFF999999SFS51A/Working/Logs/Mobius/.
strFileName to move is Archive.log
Moving File
Moving on with //WFF999999SFS51A/Working/Logs/Mobius/.
strFileName to move is Copyoftest.txt
Moving File
Moving on with //WFF999999SFS51A/Working/Logs/Mobius/.
strFileName to move is test.txt
Moving File
Moving on with //WFF999999SFS51A/Working/Logs/Mobius/.
strFileName to move is Copy4oftest.txt
Moving File
Moving on with //WFF999999SFS51A/Working/Logs/Mobius/.
strFileName to move is Copy3oftest.txt
Moving File
Moving on with //WFF999999SFS51A/Working/Logs/Mobius/.
strFileName to move is VDRNET
Creating Subdirectory.
MoveFiles called for Directory: //WFF999999SFS51A/Working/Logs/Mobius/VDRNET/
strFileName to move is .
File is . or .. -- skipping file
Moving on with //WFF999999SFS51A/Working/Logs/Mobius/VDRNET/.
strFileName to move is ..
File is . or .. -- skipping file
Moving on with //WFF999999SFS51A/Working/Logs/Mobius/VDRNET/.
strFileName to move is Copy5oftest.txt
Moving File
Moving on with //WFF999999SFS51A/Working/Logs/Mobius/VDRNET/.
strFileName to move is Copyoftest.txt
Moving File
Moving on with //WFF999999SFS51A/Working/Logs/Mobius/VDRNET/.
strFileName to move is test.txt
Moving File
Moving on with //WFF999999SFS51A/Working/Logs/Mobius/VDRNET/.
strFileName to move is Copy4oftest.txt
Moving File
Moving on with //WFF999999SFS51A/Working/Logs/Mobius/VDRNET/.
strFileName to move is Copy3oftest.txt
Moving File
Moving on with //WFF999999SFS51A/Working/Logs/Mobius/VDRNET/.
strFileName to move is Copy2oftest.txt
Moving File
Moving on with //WFF999999SFS51A/Working/Logs/Mobius/VDRNET/.
strFileName to move is AuditServerOutput.csv
Moving File
Moving on with //WFF999999SFS51A/Working/Logs/Mobius/VDRNET/.
Back from recursed execution
Moving on with //WFF999999SFS51A/Working/Logs/Mobius/.
Current Log Folder = QMaster


At issue is the fact that in addition to the VDRNET folder, which it recurses into and empties as it should, there is a folder ...\Mobius\ArchiveCreation which is never even enters.

I am settring the point values on this as high as possible, as it is for a project at work that I really need to get completed.

Thank you.

Greg H
LVL 2
JzaltheralAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
try
     my @files = grep !/^\.\.?/,readdir MOVEFILE;
     
#2: Read file name, if . or .. ignore file
     for $strFileName ( @files ){
         print "strFileName to move is $strFileName\n";
         ...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ozoCommented:
or try
local *MOVEFILE;
0
ozoCommented:
although that could limit the depth of recurson to the number of open files your system allows.
0
JzaltheralAuthor Commented:
Ozo,

Your first suggestion was exactly what I needed.  I changed a few lines of code and it works like a champ.

Thank you, and enjoy the points!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.