Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Hayley Risley](https://secure.gravatar.com/avatar/96c30601450dbf37a62b533b12608b62?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Hayley Risley
9,510 Pointshow do you create a python script that collects file name, size, and date created
I am trying to create a simple python application that takes two parameters and collects all the file names, size, and date created in a given folder. I have looked on Google and browsed online tutorials and I'm still not sure how to go about this. Any and all help/guidance is appreciated.
2 Answers
![Kevin Esther](https://uploads.teamtreehouse.com/production/profile-photos/4987/micro_DSC_0164.jpg)
Kevin Esther
8,551 PointsHi Hayley,
I started reading the os module and path documentation as I wanted to give this a try myself.
I came across the attributes relating to size etc....
It was a bit of trial and error below is some code that might of of use for creating your function.
I find reading the documentation first is better than turning straight to stack overflow, tutorials etc...
If I go to stack overflow it just too much information and often leads me down a rabbit hole.
import os
from path import Path
import datetime
import time
# check the current directory
cwd = os.getcwd()
# change current directory
cwd = Path('C:/Users/name/Documents/test')
for file in cwd.files():
file_name = file
last_Mod = os.stat(file).st_ctime
size = os.stat(file).st_size
print(file_name)
print(size)
print(datetime.datetime.strptime(time.ctime(last_Mod), "%a %b %d %H:%M:%S %Y"))
I found this helpful as never done it before.
![Andrew Uzoka](https://secure.gravatar.com/avatar/2a80465effa4f2397ff8bb9af33b1f07?s=60&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Andrew Uzoka
1,949 PointsHi, where would you read the documentation for python. could you send me a link
![Steven Parker](https://uploads.teamtreehouse.com/production/profile-photos/969492/micro_tool_chess_set_2.jpg)
Steven Parker
230,688 PointsTry the online Python Language Reference.
But next time, start a new question instead of posting one as a comment to an old question.
![Moath Mha](https://secure.gravatar.com/avatar/8a9bdabb0d5c76cba0dc300cfe894a78?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Moath Mha
Python Web Development Techdegree Student 1,663 PointsI got an error
line 2, in <module> from path import Path ModuleNotFoundError: No module named 'path'
![Kevin Esther](https://uploads.teamtreehouse.com/production/profile-photos/4987/micro_DSC_0164.jpg)
Kevin Esther
8,551 PointsHi Moath, think ran this in the terminal so that why it worked for me.
If you change the line to that should work.
from pathlib import Path
Steven Parker
230,688 PointsSteven Parker
230,688 PointsIt's not clear what the relationship is between the "two parameters" and the "file name, size, and date". But in any case, it would be helpful to post your current code, preferably as a link to a workspace snapshot.