파일 .fdf
을 가져 와서 외부 명령을 사용하여 다른 형식 .g
으로 변환하려고합니다. 거기에서 소스 FDF를 백업 폴더로 이동하고 g 파일을 임시 폴더로 이동하려고합니다. 새 파일 경로 생성이 작동하지 않습니다.
private void populateTable(string[] paths)
{
string fdf_g = System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "Local\\FindReplace\\Bin\\fdf_g.exe";
string g_fdf = System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "Local\\FindReplace\\Bin\\g_fdf.exe";
System.Collections.Generic.List <string> gFiles = new System.Collections.Generic.List<string>();
foreach (string file in paths)
{
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.FileName = fdf_g;
startInfo.Arguments = file;
System.Diagnostics.Process.Start(startInfo);
System.IO.File.Copy(file, System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "Local\\FindReplace\\BackupFDF\\" + System.IO.Path.GetFileName(file));
System.IO.File.Move("FOX_" + System.IO.Path.GetFileName(file).Replace(".fdf",".g"), System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "Local\\FindReplace\\Temp\\" + "FOX_" + System.IO.Path.GetFileName(file).Replace(".fdf", ".g"));
gFiles.Add(System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "Local\\FindReplace\\Temp\\" + "FOX_" + System.IO.Path.GetFileName(file).Replace(".fdf", ".g"));
}
foreach (string file in gFiles)
{
System.IO.StreamReader gFile = new System.IO.StreamReader(file);
string line = "";
while ((line = gFile.ReadLine()) != null)
{
foreach (string template in templates)
{
if (line.Contains(template) && !templatesInSelection.Contains(template))
{
templatesInSelection.Add(template);
}
}
}
}
findReplaceGrid.AutoGenerateColumns = false;
findReplaceGrid.DataSource = templatesInSelection;
}
변환이 잘 노력하고 있습니다.
Additional information: Could not find file 'C:\Users\James.Hughes\Source\Repos\Find-and-Replace-Symbols\Find and Replace Symbols\bin\Debug\FOX_18_83_COD_002.g'.
변환 유틸리티는 따라서이 형식 FOX_%origName%.g
원본 파일 경로의 문자열 조작을 사용하여 파일 이름을 바꿉니다 제외
System.IO.File.Move("FOX_" + System.IO.Path.GetFileName(file).Replace(".fdf",".g"), System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "Local\\FindReplace\\Temp\\" + "FOX_" + System.IO.Path.GetFileName(file).Replace(".fdf", ".g"));
:이 프로그램은, 그러나, 라인 독서에 예외가 발생합니다 새로운 이름을 얻으십시오.
내가 이해할 수없는 것은 appdata에서 찾아야 할 때 C:\Users\James.Hughes\Source\Repos\Find-and-Replace-Symbols\Find and Replace Symbols\bin\Debug\FOX_18_83_COD_002.g'
에 액세스하려고 시도하는 이유입니다.
나는 어떤 도움을 주시면 정말 놀랐습니다!
전체적으로 코드를 복제하는 대신 폴더 경로를 한 번만 가져 오는 것이 도움이 될 것입니다. 그리고 경로를 로컬에 추가하는 것이 아니라 적절한 특수 폴더를 사용하십시오. 그리고 문자열 연결 대신 Path.Combine을 사용하십시오. 이 방법으로 잠재적 인 경로 오류를 많이 피할 수 있으며 액세스하려는 경로를 쉽게 볼 수 있습니다. 또한 문자열 앞에 @를 사용하면 모든 곳에서 백 슬래시를 벗어날 필요가 없습니다. 코드를 간결하고 읽기 쉽게 만듭니다. – ManoDestra
좋습니다, 고맙지 만 문제는 해결되지 않는 것 같습니다 –
오류가 발생한 위치를 볼 수 있도록 콘솔을 사용하기 전에 콘솔에서 경로를 출력하십시오. – ManoDestra