Accessing all files from a drive

I was trying to access all revit family files through the below code. but I got error that access denied. how can I exclude access denied folders in search?

from System.IO import Directory, SearchOption
Directory.GetFiles(“C:/”, “*.rfa”, SearchOption.AllDirectories)

Log in as local admin (full access to the C drive), disable any security settings which would block full stop trawlers (many potentials here), and then run the code.

Find in Windows would likely be faster and less problematic.

@jacob.small hi, i don’t want to access the access denied folders. i just want to exclude my search from those folders. Is it possible?

You would have to narrow your search scope - day just your user profile not the whole of the C drive (which could include other profiles).

@jacob.small - I am making a dynamo to place the hangers over duct. it is working perfectly if the hanger family loaded. At present I given a permanent path to load the family if it is not loaded. That also working perfectly. Now I wish to rewrite the code in such a way that if the family not loaded code need to ask a path to user or it need to search the specific family in all folders in the system. Is there any way to do like that?

Look into Datashapes UI++ nodes as they have the ability to ‘ask for a user path’ when run. This can be run (or not) based on the family not existing in the file (or existing). Then the user just picks the family they want to use manually, which isn’t much work in the grand scheme of things. Could be faster if you had a static path to start browsing from (say to the office standard family path).

def findPath ():
dialog = FolderBrowserDialog()
s = dialog.ShowDialog()
if s == DialogResult.OK:
path = dialog.SelectedPath
return path