Buenos Dias,
Estoy intentando realizar copia de archivos desde la carpeta A hasta la carpeta B. El nombre del archivo obtengo desde una hoja excel, y de ahí utilizo la función copy file sin ningún inconveniente. El problema se cuando deseo copiar archivos que contenga un nombre en especifico, ejemplo
coincidencia a busca: ABS
nombre de archivo 1: ABS_1.JPG
nombre de archivo 2: ABS_2.JPG
mi inquietud es como enviar un like o un contains , para que busque la coindicencia en mis archivos y los copie en este ejemplo seria a los dos archivos.
Here is the logic I use when saving a file without overwriting it where DownloadPath is you intended save full path (with some modifications to fit your case and a little verbose).
The While loop is entered only if the intended path already exists.
I used other approaches based on Directory.GetFiles but I prefere this one.
-
Assign (String)
DownloadFolder = Environment.ExpandEnvironmentVariables(%USERPROFILE%\Pictures\Imagenes")
-
Assign (String)
DownloadPath = Path.Combine(DownloadFolder, "ABS.jpg")
-
Assign (String)
Stem = Path.GetFileNameWithoutExtension(DownloadPath)
-
Assign (String)
Extension = Path.GetExtension(DownloadPath)
-
Assign (Int32)
i = 0
-
While
File.Exists(DownloadPath)
-
Assign
i = i + 1
-
Assign (String)
FileName = String.Format("{0}_{1}_{2}", Stem, i.ToString, Extension)
-
Assign
DownloadPath = Path.Combine(DownloadFolder, FileName)
-
Thank you