c# 4.0 - How to Read Files from DVD/CD using C# -


i want read files removable disk's(cd/dvd). using below code i'm able find drive.

managementobjectsearcher mos = new managementobjectsearcher("select *    win32_diskdrive");  foreach (managementobject mo in mos.get()) { var name=mo["caption"].tostring(); var drive=mo["drive"].tostring(); var id=mo["id"].tostring(); }   

now want read files dvd.... appreciated.. in advance!!

i'm not entirely sure mean when "read files form dvd", can use following of files on each of cd/dvd drives

static ienumerable<string> getdirectoryfilepaths(string path) {     list<string> filepaths = new list<string>();      try     {         // recursively through of folders         foreach (var dir in directory.getdirectories(path, "*"))         {             filepaths.addrange(getdirectoryfilepaths(dir));         }     }     catch (unauthorizedaccessexception)     {         // skip stuff     }      // add files directly in current drive/folder     filepaths.addrange(directory.getfiles(path, "*").tolist());      return filepaths; }  static void main(string[] args) {     // of ready cd drives     foreach (var cddrive in driveinfo.getdrives().where(d => d.drivetype == drivetype.cdrom && d.isready))     {         // start @ drive , of files recursively         ienumerable<string> drivefiles = getdirectoryfilepaths(cddrive.name);          foreach (var file in drivefiles)         {             // files...             using (filestream fs = file.openread(file))             {                 //...             }         }     } } 

obviously can change code grab specific drive rather looking @ available, gets going.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -