그래서 여러 파일과 심지어 단일 파일의 이름을 바꾸는 방법을 알고 있습니다. 나는 이름을 너무 늘리는 방법을 안다. 하지만 내가 고민하는 것은 1 개의 단일 파일, db에서 많은 다른 이름의 이름을 바꾸는 것입니다. 예를 들어 textFile.txt
을 db ("file", "dog", "cat", "etc...")
에서 오는 strings
이라는 100 개의 다른 이름으로 바꿉니다. DB에 연결을 설정 한 후에 도움이 필요합니다. 거기서 어디로 가야합니까? 어떤 일종의 IEnumerable
이 필요한 것 같아요. 그리고 나서 forearch
을 반복합니다. 그냥 쓰는 법을 모르겠다. 참고로 ConsoleApp을 사용하고 있습니다. 감사!이름 바꾸기 데이터베이스에서 여러 다른 이름을 1 개 파일
class Program
{
public static void Main(string[] args)
{
SqlConnection Locations = new SqlConnection(ConsoleApplication1.Properties.Settings.Default.locationsDB);
string sourcePath = @"C:\Users\1\Desktop\a";
string targetPath = @"C:\Users\1\Desktop\b";
CopyDirectory(sourcePath, targetPath);
}
public static void CopyDirectory(string sourcePath, string targetPath)
{
if (!System.IO.Directory.Exists(targetPath))
{
System.IO.Directory.CreateDirectory(targetPath);
}
if (System.IO.Directory.Exists(sourcePath))
{
SqlConnection Locations = new SqlConnection(ConsoleApplication1.Properties.Settings.Default.locationsDB);
string[] files = System.IO.Directory.GetFiles(sourcePath);
foreach (string sourceFilePath in files)
{
for (int i = 1; i <= 4; ++i)
{
string fileExt = System.IO.Path.GetExtension(sourceFilePath);
string sourceFileName = System.IO.Path.GetFileName(sourceFilePath);
string targetFilePath = System.IO.Path.Combine(targetPath, "10000" + i + fileExt);
System.IO.File.Copy(sourceFilePath, targetFilePath);
}
break;
}
}
}
}
출력은 (
100001
100002
100003
100004
110001
110002
110003
110004
111001
111002
111003
111004
etc...