C sharp - BUscar imagen dentro de subcarpeta

 
Vista:
sin imagen de perfil

BUscar imagen dentro de subcarpeta

Publicado por Ruben Dario (23 intervenciones) el 25/01/2016 17:10:40
Buenas tardes

Alguein me podría ayudar con mi codigo, ahora mismo lo tengo un lio

Lo que necesito es buscar dentro de carpetas y subcarpetas (varias), una imagen y copiar en otra carpeta,
Lo que hago es una consulta SQL luego a partir de esa consulta obtengo el nombre del archivo que coincide con mi imagen.

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
private void button1_Click(object sender, EventArgs e)
{
	using (MySqlConnection cnges = new MySqlConnection(sqlconnection))
	{
		cnges.Open();
		string queryconuslta1 = @"select a.codigo, a.bianhao, a.namecn, a.baozhuangshu, a.zhuangxiangshu, p.precio, a.beizhu from articulo a, art_precio p
						where a.codigo=p.codigo and  beizhu = 'MP' and a.jinyong=0
						group by a.codigo order by a.codigo";
 
		MySqlCommand comando = new MySqlCommand(queryconuslta1, cnges);
		MySqlDataReader reader = comando.ExecuteReader();
 
		while (reader.Read())
		{
			string ubicacion = @"C:\images";
			string destino = @"C:\fotos\borrarruben";
 
			string fileName = Convert.ToString(reader["codigo"] + ".jpg");  //Aqui deberia ir los registros de la tabla
 
 
			foreach (string d in Directory.GetDirectories(ubicacion,fileName, SearchOption.AllDirectories))
			{
			foreach (string f in Directory.GetFiles(d, fileName))
			{
 
				System.IO.File.Copy(d, f, true);
 
			}
 
			}
 
 
 
 
			string sourceFile = System.IO.Path.Combine(ubicacion, fileName);
			string destFile = System.IO.Path.Combine(destino, fileName);
 
			if (!System.IO.Directory.Exists(destino))
			{
				System.IO.Directory.CreateDirectory(destino);
			}
 
			if (System.IO.Directory.Exists(ubicacion))
			{
				//string[] files = Directory.GetFiles("C:\\", "*.dll");
				string[] files = Directory.GetDirectories(ubicacion);
				foreach (string s in files)
				{
					fileName = System.IO.Path.GetFileName(s);
					destFile = System.IO.Path.Combine(destino, fileName);
					System.IO.File.Copy(s, destFile, true);
				}
			}
 
		//    System.IO.File.Copy(sourceFile, destFile, true);
		}
		reader.Close();
		cnges.Close();    //cerramos la conexion
 
	}
}

Si alguein me puede ayudar porfavor

Saludos
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder