'How do i iterate through a directory, and print out the file names and their sizes and make the printout clean looking?

The code i am currently working on, enters a directory. Once in that directory I need to iterate through the files in that directory and print the file names and extensions, along with the file size.

os.chdir(Path('pets', 'cats'))

current = Path.cwd()
for file in os.listdir(current):
    fileName = os.path.split(file)
    fileSize = os.path.getsize(file)
    print(str(fileName) + ': ' + str(fileSize))

The issue I am having is that the printout includes ('' '<filename.ext>'). I want to omit all these extra characters and just have <filename.ext>. Any clues on how I can clean this up?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source