As a coding project, I’m working on a file backup application, but I can’t see how to get a list of files. The idea is (and this could be the wrong approach) to build an operational manifest (the format for which I have yet to establish), but I can’t get a list of file names.
This is some dev code that reads the file system based on a starting point set by path1
.
import easygui
import os
path1 = easygui.diropenbox(msg='Source dir')
filepaths = [os.path.join(path1, f) for f in os.listdir(path1)]
for file in os.listdir(path=path1):
print(file)
print()
for file in filepaths:
print(file)
Note: I’m using easygui
just for the dev and may migrate this to a full Tkinter front-end, if needs be. Some of the above code is from here.
The output (on my system: a Debian based OS):
dev1.py
read_me
test_files
test_bu
dev2.py
/home/rob/Desktop/python/file_system_backup/dev1.py
/home/rob/Desktop/python/file_system_backup/read_me
/home/rob/Desktop/python/file_system_backup/test_files
/home/rob/Desktop/python/file_system_backup/test_bu
/home/rob/Desktop/python/file_system_backup/dev2.py
The issue is…
dev1.py <- a file
read_me <- a file
test_files <- a directory
test_bu <- a directory
dev2.py <- a file
As you can see, on the face of it, there seems to be no way to distinguish the files from the directories. I understand that technically and so far as the file system is concerned, there is no difference; it’s simply how the names are flagged by the file Mode
that makes them so: please correct me if I’m wrong
Is there a way to read said ‘Mode’ so that I can code the script to distinguish between different file modes and thus build said manifest?
Related to: Read/write byte objects