My source path is C:\images\
in which I have hundreds of folders called Album-1, Album-2 etc. I create a target path F:\AllPics
. And then I want to move all the files inside my albums to the target path, so that I get all the images in one folder with subfolder names like album-1_img1,album2-img2. How can I do this ?
Asked
Active
Viewed 1,015 times
-3

halfer
- 19,824
- 17
- 99
- 186

lightcoder
- 43
- 1
- 8
-
Did you even try anything? what have you done so far? SO isn't a code writing machine. – MichaelThePotato Aug 22 '16 at 11:43
-
What did you try so far ? SO is not a coding service take a look here :http://stackoverflow.com/help/how-to-ask – Quentin Roger Aug 22 '16 at 11:44
-
This has been asked so many times its ridiculous – BugFinder Aug 22 '16 at 11:55
-
Possible duplicate of [Best way to copy the entire contents of a directory in C#](http://stackoverflow.com/questions/58744/best-way-to-copy-the-entire-contents-of-a-directory-in-c-sharp) – BugFinder Aug 22 '16 at 11:56
2 Answers
0
Look at the File & Directory classes. You can iterate through the files in a directory similar to this (may need tweeks) There are options to include directories etc.
// Process the list of files found in the directory.
string [] fileEntries = Directory.GetFiles(targetDirectory);
foreach(string fileName in fileEntries)
ProcessFile(fileName);
// Recurse into subdirectories of this directory.
string [] subdirectoryEntries = Directory.GetDirectories(targetDirectory);
foreach(string subdirectory in subdirectoryEntries)
ProcessDirectory(subdirectory);

AntDC
- 1,807
- 14
- 23
-
`Directory.GetFiles()` takes a path at the very least and then a search pattern. You have also missed `"` as well. – uTeisT Aug 22 '16 at 11:52
0
namespace MassFileMoverConsole
{
class Program
{
string _sourcePath;
string _targetPath;
static void Main(string[] args)
{
Program massMover = new Program();
massMover.MoveThemAll();
}
void MoveThemAll()
{
Console.WriteLine("Enter source path : ");
_sourcePath = Console.ReadLine();
Console.WriteLine("Enter target path : ");
_targetPath = Console.ReadLine();
var subFolderNamesTargetPath = Directory.GetDirectories(_sourcePath);
foreach(var subFolderName in subFolderNamesTargetPath)
{
var subFolder = new DirectoryInfo(subFolderName);
var subFolderFiles = subFolder.GetFiles();
foreach(var subFolderFile in subFolderFiles)
{
var fileNewName = subFolder.Name + "_" + subFolderFile.Name;
subFolderFile.CopyTo(Path.Combine(_targetPath, fileNewName));
}
}
}
}
}

Arctic Vowel
- 1,492
- 1
- 22
- 34
-
1@lightcoder Happy to hear that, you're welcome! I think you got some downvotes on this question since it doesn't contain any visible code/research effort, which is generally frowned upon in SO. To avoid this in future questions it's better to look through tutorials, try to write code, and post a question if/when you get stuck. Welcome to SO :) – Arctic Vowel Aug 22 '16 at 16:07