How to set a path directory?

Hello,

i want to look at family Sizes… but my path does not work…


# get Schedules
def tolist(x):
	if hasattr(x,'__iter__'): return x
	else : return [x]

paths = 'C:/Users/MAX.WERKSTATT/OneDrive - ChaosAndPartner/Desktop/Revit_temp/966/Familien'
mb = 1048576.0
kb = 1024.0

# get Schedules
def getSize(p, mb=mb, kb=kb, kbOnly = False):
	sb = FileInfo(p).Length
	if sb < mb or kbOnly:
		return '%.3f KB' % (sb / kb)
	else:
		return '%.3f MB' % (sb / mb)

OUT = map(getSize, paths)

how to set a path correct?

KR

Andreas

I’d recommend looking into the os module, including os.walk.

@jacob.small

i tried this but it did not work

paths = os.listdir(

i get the “families” but i can`t access them, so whats going on?

oh no just text

Always check the documentation for a call you aren’t familiar with carefully. For example, this is the entry for os.listdir. Note that the returned result is the file name, and so you need to combine it with a the directory in order to get the paths which is what your next call will need.

Haven’t tested it yet, but the concepts below should get you where you want as I’ve added some extra comments to each line:

directory = IN[0] # the directory you want to get data from - tip: never hard code these.
familyFileNames = contents = [i for i in os.listdir(directory) if i.endswith(".rfa")] #get the names of the family files in the directory as a list
familyPaths = [os.path.join(directory,i) for i in familyFileNames] #create the file paths by joining the directory and file name into a single path
stats = [os.stat(i) for i in familyPaths] #get the status of each file
sizes = [i.st_size for i in stats] #get the size from each status entry
OUT = zip(familyPaths, sizes) #zip the paths and sizes into a single list

Note this utilizes the os.stat call. The the returned object from that call is an instance of the os.stat_result class, which has a lot of useful attributes beyond size of the file.

2 Likes

@jacob.small

i just bits so for KB just divide 1000…

KR

Andreas

1 Like