Ciao a tutti devo realizzare una console application che mi va a cambiare le estensioni dei file in una directory. Nella directory i file sono tutti di questo tipo :
abcd.pdf.err e abcdefg.err devo rinominarli in abcd.pdf e abcdefg.ini
questo è quello che ho fatto, innanzitutto:
DirectoryInfo dir = new DirectoryInfo("C:\\CartellaPDFERR");
FileInfo[] allFile = dir.GetFiles("*.err"); // sia pdf che ini
FileInfo[] filePdfErr = dir.GetFiles("*.pdf.err"); // tutti i pdf
FileInfo[] fileIniErr = new FileInfo[allFile.Length - filePdfErr.Length];
int indice = 0;
string controllo;
// trova tutti i file .ini.er
for (int i = 0; i <= allFile.Length-1; i++) {
bool is_the_same = false;
for (int j = 0; j <= filePdfErr.Length-1; j++)
if (allFile[i].Name.Equals(filePdfErr[j].Name)){
is_the_same = true;
break;
}
if (!is_the_same)
fileIniErr[indice++] = allFile[i];
}
A questo punto punto ho due array contenenti in uno i file .pdf.err e nell'altro i file .err
// Abbiamo i 2 array file.Pdf.Err[] e fileIni.Err[] con i .pdf.err e .err dobbiamo rinominarli se il filename di .pdf.err contiene.err.
for (int i = 0; i <= filePdfErr.Length-1; i++) {
for (int j = 0; j <= fileIniErr.Length-1; j++) {
controllo = Path.GetFileNameWithoutExtension(fileIniErr[j].Name);
if (filePdfErr[i].Name.Contains(controllo)) {
qua non so come andare avanti..... se true devo rinominare il file .err in .ini e il file .pdf.err in .pdf