audio - Opening files in another computer c# -


i have program button, when clicked, executes sound located in download folder. question how execute sound on computer if path finding different.

you need path file run it. if don't have path - have search it.

  1. pick base directory think file is. if don't know - whole drive.
  2. write recursive function search said folder recursively.
  3. test each file ever search condition is, i.e. file name, file hash, etc.

for example:

string searchforfile(string searchpath, func<string, bool> searchpredicate) {     try     {         foreach (string filename in directory.enumeratefiles(searchpath))         {             if (searchpredicate(filename))             {                 return filename;             }         }          foreach (string dirname in directory.enumeratedirectories(searchpath))         {             var childresult = searchforfile(dirname, searchpredicate);             if (childresult != null)             {                 return childresult;             }         }         return null;     }     catch (unauthorizedaccessexception)     {         return null;     } } 

usage:

var filepath = searchforfile(@"c:\", x => path.getfilename(x) == "yourfilename.mp3"); 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -