Advertisement

03.31.2006 at 09:06AM PST, ID: 21797076
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.2

Recursion breaks While Loop

Asked by Jzaltheral in Perl Programming Language

Tags:

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
Start Free Trial
 
Loading Advertisement...
 
[+][-]03.31.2006 at 10:51AM PST, ID: 16345145

View this solution now by starting your 14-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Perl Programming Language
Tags: vdrnet
Sign Up Now!
Solution Provided By: ozo
Participating Experts: 1
Solution Grade: A
 
 
[+][-]03.31.2006 at 11:28AM PST, ID: 16345479

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.31.2006 at 11:30AM PST, ID: 16345488

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.31.2006 at 12:10PM PST, ID: 16345925

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-43