bromy2004
asked on
Using System.IO.Directory.GetFiles in VB.NET
I'm trying to convert an Excel VBA Macro to VB.NET as a windows forms.
The general idea is to copy Local copies of the files to 2 other locations (1 as Template, another as XLS)
i thought i would try something new/simpler instead of the FileSystemObject
Files = System.IO.Directory.GetFil es(FullPat h, "*.xls", IO.SearchOption.AllDirecto ries)
But i get an error because there are hidden/protected system files somewhere in the subfolder.
A first chance exception of type 'System.UnauthorizedAccess Exception' occurred in mscorlib.dll
Does anyone have any ideas?
I'm using VS 2010 Beta 2
The general idea is to copy Local copies of the files to 2 other locations (1 as Template, another as XLS)
i thought i would try something new/simpler instead of the FileSystemObject
Files = System.IO.Directory.GetFil
But i get an error because there are hidden/protected system files somewhere in the subfolder.
A first chance exception of type 'System.UnauthorizedAccess
Does anyone have any ideas?
I'm using VS 2010 Beta 2
ASKER
It will be for Subfolders
"Z:\Reports\Jet Reports\"
to "N:\Quick Corporate\Forms\"
"Z:\Reports\Jet Reports\"
to "N:\Quick Corporate\Forms\"
Do you have any system folder inside "Z:\Reports\Jet Reports\"?
ASKER
No there shouldn't be.
I was testing on a separate Partition "F:", which contains Movies and Music.
the error came up when it tried to read a hidden AVG folder.
I was testing on a separate Partition "F:", which contains Movies and Music.
the error came up when it tried to read a hidden AVG folder.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
jpaulino's solution is correct. What the Framework despirately needs is a "ContinueOnError" option for their recursive File System routines... but alas, there currently isn't one... and isn't one planned for .Net 4.0
Since you were getting a permission denied before, I'd recommend you alter the example above to detect (and ignore) exception conditions.
Since you were getting a permission denied before, I'd recommend you alter the example above to detect (and ignore) exception conditions.
...never mind... I see it already has exception support.
My bad...
My bad...
You have some examples in EE that you can use about recursive functions to loop in all directories