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.
- pick base directory think file is. if don't know - whole drive.
- write recursive function search said folder recursively.
- 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
Post a Comment