tester sur le chemin pour savoir si c'est un fichier ou un dossier (directory)
par contre j'ai une question
mtnt je peux compresser un dossier D1 contenant des fichiers f1, f2,...
en un dossier D1compressed contenant des fichiers f1.gz,f2.gz,...
mais s'il y a d'autres dossiers D2 dans D1 il fait rien
donc ce que je veux c'est tester si c'est un dossier ou un fichier
est ce que quelqu'un a une idée comment faire ??
merci d'avance
comment faire quand il plus qu'un seul sous repertoire dans le meme niveau?
ca marche pas
par contre j'ai reussi mtnt à compresser un repertoire mais à condition qu'il y ait un seul sous repertoire dans chaque niveau
je sais pas comment faire quand c'est 2 ou plus ???
voici mon code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
private : String ^path;
private : String ^pathnew;
public : String ^file;
public :array<String ^> ^ files;
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
array<String ^> ^ directories;
CompressDir(textBox1->Text, textBox2->Text);
directories = Directory::GetDirectories(path);
while(directories->Length != 0)
{
for each (String ^dir in directories)
{
String ^u= dir->Substring(path->Length);
DirectoryInfo^ di = Directory::CreateDirectory(pathnew+u+"compressed");
String ^dirnew=pathnew+u+"compressed";
CompressDir(dir,dirnew);
directories = Directory::GetDirectories(dir);
}
}
}
void CompressDir(String ^dirSource, String ^ dirDestination)
{
path = dirSource;
pathnew = dirDestination;
files = Directory::GetFiles(path);
DirectoryInfo^ di = Directory::CreateDirectory(pathnew);
for each (file in files)
{
String ^v= file->Substring(path->Length);
System::Windows::Forms::MessageBox::Show(v);
if (!compresserFichier(file, pathnew+v+".gz"))
Console::WriteLine("failure in compression");
}
} |
pour une fois je me répond
j'ai réussi à faire une méthode "CompressDir"qui compresse un dossier D en un dossier Dcompressed et une autre qui decompresse , voici mon code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
void CompressDir(String ^dirSource, String ^ dirDestination)
{
String ^file;
array<String ^> ^ directories;
array<String ^> ^ files;
String ^path = dirSource;
String ^pathnew = dirDestination;
files = Directory::GetFiles(path);
DirectoryInfo^ di = Directory::CreateDirectory(pathnew);
for each (file in files)
{
String ^v= file->Substring(path->Length);
if (!compresserFichier(file, pathnew+v+".gz"))
Console::WriteLine("failure in compression");
}
directories = Directory::GetDirectories(path);
for each (String ^dir in directories)
{
String ^u= dir->Substring(path->Length);
System::Windows::Forms::MessageBox::Show("u "+u);
String ^dirnew=pathnew+u+"compressed";
System::Windows::Forms::MessageBox::Show("pathnew "+pathnew);
CompressDir(dir,dirnew);
}
}
void DecompressDir(String ^dirSource, String ^ dirDestination)
{
String ^file;
array<String ^> ^ directories;
array<String ^> ^ files;
String ^path = dirSource;
String ^pathnew = dirDestination;
files = Directory::GetFiles(path);
DirectoryInfo^ di = Directory::CreateDirectory(pathnew);
for each (file in files)
{
String ^v= file->Substring(path->Length);
int i = v->Length;
i = i-3;
String ^v1 = v->Substring(0,i);
System::Windows::Forms::MessageBox::Show("v1 "+v1);
if (!decompression(file, pathnew+v1))
Console::WriteLine("failure in compression");
}
directories = Directory::GetDirectories(path);
for each (String ^dir in directories)
{
String ^u= dir->Substring(path->Length);
String ^dirnew=pathnew+u+"decompressed";
DecompressDir(dir,dirnew);
}
}
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
DecompressDir(textBox1->Text, textBox2->Text);
} |