开发者

How to store folders/files tree

I design a multi-threaded application that will monitor and handle files in selected folders (accordi开发者_StackOverflow社区ng to user preference).

What is the best way to store information on the files ? (e.g. User add xxx directory, I need to go over the directory and add all the files and sub dir to my application)

I was considering my own tree structure or using SQLite.

Thanks


SQLite is a nice solution, as the database wrapper will handle locking of reads and writes (within the database) for you. You can even use a column as your file's read/write lock.


It depends on your environment, size and type of project, etc.

The EASIEST way is to use the pickle.

For example the data is in a tuple in this format:

actions=(
    {time=..., user=..., action="adddir", name="new folder"},
    {time=..., user=..., action="accessfile", name="/etc/passwords"}
)

#save the data:
f = open('somefile', 'w');
pickle.dump(actions, f)
f.close()

#laod them:
f = open('somefile', 'r');
actions = pickle.load(f)
f.close()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜