폴더안의 txt문서들을 전부 폴더명.txt로 변경함.
일단 한번 쓰고 버릴 목적의 코드기 때문에 딱히 더 발전시킬 생각은 없음.
필요하신분들은 수정해서 잘 쓰세요.
----------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.IO;
namespace txtchanger
{
class Program
{
static void Main(string[] args)
{
string targetDir = @"F:\[Download]"; // 검색할 디렉토리
string moveDir = "F:\\[Download]\\Done\\[읽을거리]\\"; // 완료후 이동할 디렉토리
string bookTitle;
string newfileName;
int cnt;
foreach (string dirName in Directory.GetDirectories(targetDir))
{
// 현재 디렉토리 명(책제목) 구하기
bookTitle = dirName.Substring(targetDir.Length, dirName.Length - targetDir.Length);
cnt = 0;
foreach (string fileName in Directory.GetFiles(dirName, "*.txt"))
{
// TXT 파일을 책제목으로 변환함. 여러파일일 경우 _1, _2, _3식으로.
if (cnt == 0)
{
newfileName = string.Format("{0}\\{1}.txt", moveDir, bookTitle);
}
else
{
newfileName = string.Format("{0}\\{1}_{2}.txt", moveDir, bookTitle, cnt.ToString());
}
cnt++;
if(File.Exists(newfileName))
{
newfileName = string.Format("{0}_", newfileName);
}
File.Move(fileName, newfileName);
}
}
}
}
}
이 글과 관련있는 글을 자동검색한 결과입니다 [?]