简体   繁体   English

在python中中断os.rename

[英]Interruption of a os.rename in python

I made a script in python that renames all files and folders(does not recurse ) in "." 我用python编写了一个脚本,将“。”中的所有文件和文件夹重命名(不递归 )。 directory: the directory in which file is kept. directory:保存文件的目录。 It happened that I ran the script in a directory which contained no files and only one directory let's say imp with path .\\imp . 事有凑巧,我跑了剧本中不包含的文件,只有一个目录让我们说小鬼与路径的目录.\\imp While program was renaming it, the electricity went off and the job was interrupted (sorry did't had UPS). 程序重命名时,电源关闭,工作中断(对不起,没有UPS)。

Now as the name suggests, assume imp contains important data. 现在,顾名思义,假设imp包含重要数据。 The renaming process also took quite good time ( compared to others ) before electricity went off even when all it was renaming was one folder. 重命名过程还需要相当长的时间(与其他相比),即使断电只是一个文件夹,也要等到断电。 After this endeavour is some data corrupted, lost or anything? 经过这一努力之后,某些数据已损坏,丢失或发生了什么?

Just make this more useful: what happens os.rename is forced to stop when it is doing its job? 只是使它更有用:当os.rename工作时会被迫停止吗? How is the effect different for files and folders? 文件和文件夹的效果有何不同?

Details 细节

Python Version - 2.7.10 Python版本 -2.7.10

Operating System - Windows 10 Pro 作业系统 -Windows 10 Pro

You are using Windows, which means you are (probably) on NTFS. 您正在使用Windows,这意味着(可能)您正在使用NTFS。 NTFS is a modern, journaling file system. NTFS是一种现代的日记文件系统。 It should not corrupt or lose any data, though it's possible that only some of the changes that constitute a rename have been applied (for instance, the filename might change without updating the modification time, or vice-versa ). 它不应损坏丢失任何数据,尽管有可能仅应用了构成重命名的某些更改(例如,文件名可能会更改而不更新修改时间, 反之亦然 )。 It is also possible that none of those changes have been applied. 这些更改也可能未应用。

Note the word "should" is not the same as "will." 请注意,单词“应该”与“将要”不同。 NTFS should not lose data in this fashion, and if it does, it's a bug. NTFS 不应以这种方式丢失数据,如果这样做,那就是一个错误。 But because all software has bugs, it is important to keep backups of files you care about. 但是,因为所有软件都有错误,所以重要的是要备份您关心的文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM