Click here to Skip to main content
15,881,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i need to copy all the images from usb drive to local folder.currently i got the logical drive name.(my usb drive name is G).
Posted
Updated 31-Dec-12 22:45pm
v2

Try something like this:
C#
string usbRoot = @"H:\";
string destFolder = @"C:\CopiedTo";
string[] files = Directory.GetFiles(usbRoot, "*.jpg", SearchOption.AllDirectories);
foreach (string file in files)
    {
    string dest = destFolder + file.Substring(usbRoot.Length);
    if (!Directory.Exists(Path.GetDirectoryName(dest)))
        {
        Directory.CreateDirectory(Path.GetDirectoryName(dest));
        }
    File.Copy(file, dest, true);
    }
 
Share this answer
 
Comments
josh-jw 2-Jan-13 4:25am    
here in
string[] files = Directory.GetFiles(usbRoot, "*.jpg", SearchOption.AllDirectories);
i am not getting the files.the project is running mode,still waiting,and no response
You can always check if a USB device is connected - A USB Library to Detect USB Devices[^].
Once this is done, read the drive just like you would read any other drive.
Use directory operations, you can read through the directory structure( http://support.microsoft.com/kb/303974[^]) and filter out the image files.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900