English 中文(简体)
Set file property in Zhu
原标题:Set file properties in Python

在Filemanager(Windows)中,我可以正确地点击档案,看看其特性。 我愿用沙尔来抓他们。 这似乎很复杂。 有了os,我可以收回标准档案财产,但我不能确定(tom)财产。 C# 似乎有解决办法。 检索元数据栏目,用于视觉基础

 setattr(file, property_name, property_value) 

但这并不可行。

问题回答

Check out this answer.

有了几个模块,你就可以改变,例如,用@Claudiu解决方案创造时间:

import pywintypes, win32file, win32con
def changeFileCreationTime(fname, newtime):
    wintime = pywintypes.Time(newtime)
    winfile = win32file.CreateFile(
        fname, win32con.GENERIC_WRITE,
        win32con.FILE_SHARE_READ | win32con.FILE_SHARE_WRITE | win32con.FILE_SHARE_DELETE,
        None, win32con.OPEN_EXISTING,
        win32con.FILE_ATTRIBUTE_NORMAL, None)

    win32file.SetFileTime(winfile, wintime, None, None)

    winfile.close()

页: 1 我不敢确定是否有关于Pywin32的具体文件,但这些类型的模块通常围绕管理系统更新项目,如VBA或C#进行总结。 因此,找到答案往往非常容易。 MS C# docs(根据我在办公室应用方面的经验)。 这可能有助于你确定任何任意财产。

Do not try to set metadata for files in Python. Because even if it would be possible, copying the file might lose the metadata, see http://docs.python.org/3/library/shutil.html#module-shutil This mean using metadata will result to unpredictable results. Which is bad. Better something is not possible at all, then being unpredictable.

Work around : I created an addition textfile meta.txt and archived these files using :

shutil.make_archive

根本不是美丽的。 但是,这一档案档案可以复制,而没有改变元数据。 如果档案中的所有元数据都无序可查。





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签