2016-08-22 4 views
-3

내 원본 경로는 Album-1, Album-2 등의 수백 개의 폴더가있는 C : \ images \입니다. 나는 taget 경로 F : \를 만듭니다. AllPics. 그런 다음 내 앨범의 모든 파일을 대상 경로로 이동하여 앨범 -1_img1, 앨범 2-img2와 같은 하위 폴더 이름이있는 한 폴더의 모든 이미지를 가져 오려고합니다. 어떻게해야합니까?하위 폴더에있는 모든 파일을 하위 폴더 이름으로 복사합니다.

+0

디렉토리를 포함하려면이 유사한 디렉토리에있는 파일 (tweeks을해야 할 수도 있습니다) 있습니다 옵션을 반복 할 수 있습니까? 지금까지 뭐 했어? 그래서 코드 작성 기계가 아닙니다. – MichaelThePotato

+0

지금까지 무엇을 시도 했습니까? 그래서 코딩 서비스는 여기를 보지 않습니다. http : //stackoverflow.com/help/how-to-ask –

+0

이것은 여러 번 그 말도 안되는 질문입니다. – BugFinder

답변

0
namespace MassFileMoverConsole 
{ 
    class Program 
    { 
     string _sourcePath; 
     string _targetPath; 

     static void Main(string[] args) 
     { 
      Program massMover = new Program(); 
      massMover.MoveThemAll(); 
     } 

     void MoveThemAll() 
     { 
      Console.WriteLine("Enter source path : "); 
      _sourcePath = Console.ReadLine(); 
      Console.WriteLine("Enter target path : "); 
      _targetPath = Console.ReadLine(); 

      var subFolderNamesTargetPath = Directory.GetDirectories(_sourcePath); 
      foreach(var subFolderName in subFolderNamesTargetPath) 
      { 
       var subFolder = new DirectoryInfo(subFolderName); 
       var subFolderFiles = subFolder.GetFiles(); 
       foreach(var subFolderFile in subFolderFiles) 
       { 
        var fileNewName = subFolder.Name + "_" + subFolderFile.Name; 
        subFolderFile.CopyTo(Path.Combine(_targetPath, fileNewName)); 
       } 
      } 

     } 
    } 
} 
+0

Aniruddha Varma .. 대단히 감사합니다. – lightcoder

+0

@lightcoder 그걸 들으니 반가워요! 나는이 질문에 downvotes가 있다고 생각합니다. 모든 눈에 보이는 코드/연구 노력은 일반적으로 눈살을 끈다. 미래의 질문에서 이것을 피하려면 자습서를보고 코드를 작성하고 문제가있을 경우 게시하십시오. –

0

파일 & 디렉토리 클래스를 확인하십시오. 당신은 당신도 아무것도 시도해 봤어 등

// Process the list of files found in the directory. 
string [] fileEntries = Directory.GetFiles(targetDirectory); 
foreach(string fileName in fileEntries) 
    ProcessFile(fileName); 

// Recurse into subdirectories of this directory. 
string [] subdirectoryEntries = Directory.GetDirectories(targetDirectory); 
foreach(string subdirectory in subdirectoryEntries) 
    ProcessDirectory(subdirectory); 
+0

'Directory.GetFiles() '는 최소한 길을 찾은 다음 검색 패턴을 취합니다. 당신은 또한'''도 놓쳤습니다. – uTeisT

관련 문제