c# - Why am I getting ArgumentException? -


this code:

t = environment.getenvironmentvariable("userprofile")+"\\documents"; string[] txtfiles = directory.getfiles(t, "*.txt",searchoption.alldirectories); var textfiles = txtfiles.selectmany(x => directory.getfiles(t, x)); 

i want text files documents directory , subdirectories. before did changes code was:

string[] txtfiles = directory.getfiles(t, "*.txt",searchoption.alldirectories); 

and worked.

but did changes since want later directory size , other stuff. problem on line:

var textfiles = txtfiles.selectmany(x => directory.getfiles(t, x)); 

i'm getting exception:

second path fragment must not drive or unc name 

the variable t contain: c:\users\bout0_000\documents variable x contain: c:\users\bout0_000\documents\3dmark\3dmarkerror.txt

so why before worked , after changes did in code i'm getting exception ?

you seem trying list of files using directory.getfiles on filename not directory path

i assuming want list of directorys contained files, use:

   var textfiles = txtfiles.select(x => system.io.path.getdirectoryname(x)).distinct(); 

Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -