Wednesday, January 23, 2013

주어진 filepath 가 존재할 경우 available 한 다른 파일명을 얻어내는 함수

 sub availableFilename  
 {  
      my $givenFilepath = shift;  
      if(-e $givenFilepath){  
           my ($dir, $filenameOnly, $ext) = filepathParse($givenFilepath);  
           my $virgin = 1;  
           my $otherFilepath = "";  
           for(my $i = 1; $i < 80; $i++){  
                $otherFilepath = $dir . $filenameOnly . $ext;  
                if(!(-e $otherFilepath)){  
                     $virgin = 0;  
                     last;  
                }  
                $filenameOnly .= "_";  
           }  
           if($virgin){return "";}  
           else{return $otherFilepath;}  
      }else{  
           return $givenFilepath;  
      }  
 }  

No comments:

Post a Comment