elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Sigue las noticias más importantes de seguridad informática en el Twitter! de elhacker.NET


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP) (Moderador: kub0x)
| | | |-+  COMO MOVER UNA CARPETA Y SU CONTENIDO DE UN VOLUMEN(D:) A OTRO(E:)
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: COMO MOVER UNA CARPETA Y SU CONTENIDO DE UN VOLUMEN(D:) A OTRO(E:)  (Leído 2,605 veces)
«Vicø™»

Desconectado Desconectado

Mensajes: 4


Ver Perfil
COMO MOVER UNA CARPETA Y SU CONTENIDO DE UN VOLUMEN(D:) A OTRO(E:)
« en: 10 Enero 2014, 14:53 pm »

Hola devs... pues tengo aqui un pequeño problema que no se como resolverlo. Pasa que estoy haciendo un programa que me pueda guardar carpetas en otras rutas pero solo funciona cuando se trata de una direccion que pertenezca al mismo volumen o particion de disco o disco local o como lo quieran llamar. El codigo que tengo es este.

Código
  1. System.IO.Directory.Move(@"E:\fotos", @"D:\fotos2");

Como podran ver lo que quiero es mover mi carpeta fotos que se encuentra en el volumen E: a la carpeta llamada fotos2 en el volumen D: y la excepcion que me sale es. El destino no puede ser otro volumen de disco ni un directorio con el mismo nombre

¿Me podrian dar alguna solucion para poder realizar esta operacion? De antemano se los agradeceria


« Última modificación: 10 Enero 2014, 20:37 pm por Eleкtro » En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.813



Ver Perfil
Re: COMO MOVER UNA CARPETA Y SU CONTENIDO DE UN VOLUMEN(D:) A OTRO(E:)
« Respuesta #1 en: 10 Enero 2014, 20:50 pm »

Según MSDN:
IOException   

An attempt was made to move a directory to a different volume.

Es una limitación (no hay solución usando ese método).


¿Me podrian dar alguna solucion para poder realizar esta operacion? De antemano se los agradeceria

Un copiado recursivo de archivos, como especifica MSDN:

Código
  1. using System;
  2. using System.IO;
  3.  
  4. class DirectoryCopyExample
  5. {
  6.    static void Main()
  7.    {
  8.        // Copy from the current directory, include subdirectories.
  9.        DirectoryCopy(".", @".\temp", true);
  10.    }
  11.  
  12.    private static void DirectoryCopy(string sourceDirName, string destDirName, bool copySubDirs)
  13.    {
  14.        // Get the subdirectories for the specified directory.
  15.        DirectoryInfo dir = new DirectoryInfo(sourceDirName);
  16.        DirectoryInfo[] dirs = dir.GetDirectories();
  17.  
  18.        if (!dir.Exists)
  19.        {
  20.            throw new DirectoryNotFoundException(
  21.                "Source directory does not exist or could not be found: "
  22.                + sourceDirName);
  23.        }
  24.  
  25.        // If the destination directory doesn't exist, create it.
  26.        if (!Directory.Exists(destDirName))
  27.        {
  28.            Directory.CreateDirectory(destDirName);
  29.        }
  30.  
  31.        // Get the files in the directory and copy them to the new location.
  32.        FileInfo[] files = dir.GetFiles();
  33.        foreach (FileInfo file in files)
  34.        {
  35.            string temppath = Path.Combine(destDirName, file.Name);
  36.            file.CopyTo(temppath, false);
  37.        }
  38.  
  39.        // If copying subdirectories, copy them and their contents to new location.
  40.        if (copySubDirs)
  41.        {
  42.            foreach (DirectoryInfo subdir in dirs)
  43.            {
  44.                string temppath = Path.Combine(destDirName, subdir.Name);
  45.                DirectoryCopy(subdir.FullName, temppath, copySubDirs);
  46.            }
  47.        }
  48.    }
  49. }

+ Otro método de uso genérico:

Cita de: Google
Código
  1. public static  void CopyAll(DirectoryInfo source, DirectoryInfo target)
  2. {
  3.    // Check if the target directory exists, if not, create it.
  4.    if (Directory.Exists(target.FullName) == false)
  5.    {
  6.        Directory.CreateDirectory(target.FullName);
  7.    }
  8.  
  9.    // Copy each file into it’s new directory.
  10.    foreach (FileInfo fi in source.GetFiles())
  11.    {
  12.        Console.WriteLine(@”Copying {0}\{1}”, target.FullName, fi.Name);
  13.        fi.CopyTo(Path.Combine(target.ToString(), fi.Name), true);
  14.    }
  15.  
  16.    // Copy each subdirectory using recursion.
  17.    foreach (DirectoryInfo diSourceSubDir in source.GetDirectories())
  18.    {
  19.        DirectoryInfo nextTargetSubDir =
  20.            target.CreateSubdirectory(diSourceSubDir.Name);
  21.        CopyAll(diSourceSubDir, nextTargetSubDir);
  22.    }
  23. }

Saludos


« Última modificación: 10 Enero 2014, 20:52 pm por Eleкtro » En línea

«Vicø™»

Desconectado Desconectado

Mensajes: 4


Ver Perfil
Re: COMO MOVER UNA CARPETA Y SU CONTENIDO DE UN VOLUMEN(D:) A OTRO(E:)
« Respuesta #2 en: 13 Enero 2014, 16:40 pm »

Muchas gracias Elektro por tu aporte, me es util pero en lo que me complica es que cuando se tratan de muchas imagenes tarda demasiado por ejemplo probe con una carpeta que pesa 5Gb y tardo como 7 minutos en terminar la operacion. Es por ese motivo que yo trataba de mover la carpeta puesto que tenia la esperanza de que se hiciera algun tipo de redireccionamiento o algo asi. Si tuvieras algun aporte mas que pudieras colaborarme respecto a este tema te estaria muy agradecido

Saludos.
En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines