Recherche de Fichier

creanova2000 Messages postés 39 Date d'inscription jeudi 31 juillet 2003 Statut Membre Dernière intervention 21 septembre 2006 - 3 déc. 2004 à 01:26
cs_coq Messages postés 6349 Date d'inscription samedi 1 juin 2002 Statut Membre Dernière intervention 2 août 2014 - 17 déc. 2004 à 08:51
creanova

Bonjour,

J'aimerai bien savoir comment je peux effectuer une recherche de fichier sur mon disque dure.

par example si je veux crerer un programme pour chercher un fichier comment je dois proceder.

je veux savoir comment cela fonctionne.

Merci

creanova.

10 réponses

cs_coq Messages postés 6349 Date d'inscription samedi 1 juin 2002 Statut Membre Dernière intervention 2 août 2014 101
3 déc. 2004 à 08:22
en parcourant toute l'arborescence à partir du rep de départ désiré en regardant dans chaque rep si le fichier ne s'y trouve pas
pour ça tu devrais trouver pas mal d'exemples de code

Cocoricoooooooo !!!!
coq
MVP Visual C#
0
cs_yoannd Messages postés 305 Date d'inscription lundi 7 janvier 2002 Statut Membre Dernière intervention 10 août 2011 7
3 déc. 2004 à 17:04
Le code suivant te permet de scanner tous les fichiers de ton disque dur. A toi de modifier le code, et principallement la fonction "InspecteFichier", pour correcpondre à ce que tu cherches.

using System;
using System.Drawing;
using System.Windows.Forms;
using System.IO;
using System.Threading;

namespace test{
public class MainForm : System.Windows.Forms.Form{
private System.Windows.Forms.Label label1;
public MainForm(){
InitializeComponent();
this.Show();

// Commencer le recherche
StartSearch("c:\");
}

public void StartSearch(string FolderName){
DirectoryInfo f = new DirectoryInfo(FolderName);
ListeRepertoire(f);
}

private void ListeRepertoire(DirectoryInfo folder){
// Inspection des fichiers
FileInfo[] files = folder.GetFiles();
foreach(FileInfo file in files){
InspecteFichier(file);
Thread.Sleep(10);
}

// Inspection des sous répertoires
DirectoryInfo[] dirs = folder.GetDirectories();
foreach(DirectoryInfo subdir in dirs){
ListeRepertoire(subdir);
Thread.Sleep(10);
}
}

private void InspecteFichier(FileInfo f){
this.label1.Text = f.Directory + "\" + f.Name;
this.Refresh();
}

[STAThread]
public static void Main(string[] args){
Application.Run(new MainForm());
}

#region Windows Forms Designer generated code
/// <summary>
/// This method is required for Windows Forms designer support.
/// Do not change the method contents inside the source code editor. The Forms designer might
/// not be able to load this method if it was changed manually.
/// </summary>
private void InitializeComponent() {
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(24, 64);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(256, 24);
this.label1.TabIndex = 0;
this.label1.Text = "label1";
//
// MainForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.label1);
this.Name = "MainForm";
this.Text = "MainForm";
this.ResumeLayout(false);
}
#endregion
}
}
0
cs_yoannd Messages postés 305 Date d'inscription lundi 7 janvier 2002 Statut Membre Dernière intervention 10 août 2011 7
3 déc. 2004 à 17:04
désolé, la mise en forme est toute chiée....... arf
0
cs_coq Messages postés 6349 Date d'inscription samedi 1 juin 2002 Statut Membre Dernière intervention 2 août 2014 101
3 déc. 2004 à 17:07
pense a utiliser la balise "code" : voir barre d'outils en dessous de la zone de saisie

Cocoricoooooooo !!!!
coq
MVP Visual C#
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
cs_yoannd Messages postés 305 Date d'inscription lundi 7 janvier 2002 Statut Membre Dernière intervention 10 août 2011 7
3 déc. 2004 à 22:56
Ha ben je la connaissait pas cette balise, j'avais pas vu qu'il y avait ca !
merki pour l'astuce !
0
creanova2000 Messages postés 39 Date d'inscription jeudi 31 juillet 2003 Statut Membre Dernière intervention 21 septembre 2006 5
4 déc. 2004 à 03:52
creanova

WOW c'est cool
Mille merci pour l'aide je vais essayer ca .

Merci

creanova
0
creanova2000 Messages postés 39 Date d'inscription jeudi 31 juillet 2003 Statut Membre Dernière intervention 21 septembre 2006 5
17 déc. 2004 à 08:00
Bonjour,

J'ai essaye d'appliquer le code qui suivrea. Le prbleme que quand je clique en dehors de la forme de l'application lors de son execution , l'application plante.
S'il vous plait comment eviter que l'application plante ?

le code est :

using System;
using System.Drawing;
using System.Windows.Forms;
using System.IO;
using System.Threading;

namespace test{
public class MainForm : System.Windows.Forms.Form{
private System.Windows.Forms.Label label1;
public MainForm(){
InitializeComponent();
this.Show();

// Commencer le recherche
StartSearch("c:\");
}

public void StartSearch(string FolderName){
DirectoryInfo f = new DirectoryInfo(FolderName);
ListeRepertoire(f);
}

private void ListeRepertoire(DirectoryInfo folder){
// Inspection des fichiers
FileInfo[] files = folder.GetFiles();
foreach(FileInfo file in files){
InspecteFichier(file);
Thread.Sleep(10);
}

// Inspection des sous répertoires
DirectoryInfo[] dirs = folder.GetDirectories();
foreach(DirectoryInfo subdir in dirs){
ListeRepertoire(subdir);
Thread.Sleep(10);
}
}

private void InspecteFichier(FileInfo f){
this.label1.Text = f.Directory + "\" + f.Name;
this.Refresh();
}

[STAThread]
public static void Main(string[] args){
Application.Run(new MainForm());
}

#region Windows Forms Designer generated code
/// <summary>
/// This method is required for Windows Forms designer support.
/// Do not change the method contents inside the source code editor. The Forms designer might
/// not be able to load this method if it was changed manually.
/// </summary>
private void InitializeComponent() {
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(24, 64);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(256, 24);
this.label1.TabIndex = 0;
this.label1.Text = "label1";
//
// MainForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.label1);
this.Name = "MainForm";
this.Text = "MainForm";
this.ResumeLayout(false);
}
#endregion
}
}

Merci de votre aide

creanova
0
cs_coq Messages postés 6349 Date d'inscription samedi 1 juin 2002 Statut Membre Dernière intervention 2 août 2014 101
17 déc. 2004 à 08:31
elle ne plante pas en fait
c'est juste que l'affichage est gelé tant que la methode de recherche n'aura pas fini

Cocoricoooooooo !!!!
coq
MVP Visual C#
0
creanova2000 Messages postés 39 Date d'inscription jeudi 31 juillet 2003 Statut Membre Dernière intervention 21 septembre 2006 5
17 déc. 2004 à 08:44
En effet ce qui se passe la fenetre devient blanche et si je clique une autre fois dedans j'ai la barre de propriete "cette application ne reponds pas"

Comment peut on resoudre ce probleme je veux dire celuis de l'affichage.

Merci de votre patience.

creanova
0
cs_coq Messages postés 6349 Date d'inscription samedi 1 juin 2002 Statut Membre Dernière intervention 2 août 2014 101
17 déc. 2004 à 08:51
en fesant la recherche dans un thread

Cocoricoooooooo !!!!
coq
MVP Visual C#
0
Rejoignez-nous