简体   繁体   English

xp上的python:errno 13权限被拒绝-文件夹中文件数的限制?

[英]python on xp: errno 13 permission denied - limits to number of files in folder?

I'm running Python 2.6.2 on XP. 我在XP上运行Python 2.6.2。 I have a large number of text files (100k+) spread across several folders that I would like to consolidate in a single folder on an external drive. 我有大量的文本文件(100k +)分布在多个文件夹中,我希望将其合并到外部驱动器的单个文件夹中。

I've tried using shutil.copy() and shutil.copytree() and distutils.file_util.copy_file() to copy files from source to destination. 我试过使用shutil.copy()和shutil.copytree()以及distutils.file_util.copy_file()将文件从源复制到目标。 None of these methods has successfully copied all files from a source folder, and each attempt has ended with IOError Errno 13 Permission Denied and I am unable to create a new destination file. 这些方法均未成功从源文件夹复制所有文件,并且每次尝试均因IOError Errno 13权限被拒绝而结束,并且我无法创建新的目标文件。

I have noticed that all the destination folders I've used, regardless of the source folders used, have ended up with exactly 13,106 files. 我注意到,无论使用什么源文件夹,我使用的所有目标文件夹最终都具有准确的13,106个文件。 I cannot open any new files for writing in folders that have this many (or more files), which may be why I'm getting Errno 13. 我无法在包含这么多(或更多文件)的文件夹中打开任何要写入的新文件,这可能就是为什么我得到Errno 13的原因。

I'd be grateful for suggestions on whether and why this problem is occurring. 感谢您提供有关是否以及为什么发生此问题的建议。

many thanks, nick 尼克,非常感谢

Are you using FAT32? 您正在使用FAT32吗? The maximum number of directory entries in a FAT32 folder is is 65.534. FAT32文件夹中的目录条目的最大数量为65.534。 If a filename is longer than 8.3, it will take more than one directory entry. 如果文件名长于8.3,它将占用多个目录条目。 If you are conking out at 13,106, this indicates that each filename is long enough to require five directory entries. 如果以13106表示,则表明每个文件名足够长,需要五个目录条目。

Solution: Use an NTFS volume; 解决方案:使用一个NTFS卷;然后使用一个NTFS卷。 it does not have per-folder limits and supports long filenames natively (that is, instead of using multiple 8.3 entries). 它没有每个文件夹的限制,并且本机支持长文件名(即,不使用多个8.3条目)。 The total number of files on an NTFS volume is limited to around 4.3 billion, but they can be put in folders in any combination. NTFS卷上的文件总数限制为43亿左右,但可以任意组合形式放置在文件夹中。

I wouldn't have that many files in a single folder, it is a maintenance nightmare. 我在一个文件夹中不会有那么多文件,这是一场维护噩梦。 BUT if you need to, don't do this on FAT: you have max. 但如果需要,请不要在FAT上执行此操作:最大 64k files in a FAT folder. FAT文件夹中的64k文件。

Read the error message 阅读错误讯息

Your specific problem could also be be, that you as the error message suggests are hitting a file which you can't access. 您的特定问题也可能是, 如错误消息所提示的那样 ,您正在击中一个无法访问的文件。 And there's no reason to believe that the count of files until this happens should change. 并且没有理由相信在这种情况发生之前文件的数量应该改变。 It is a computer after all, and you are repeating the same operation. 毕竟它是一台计算机,并且您要重复相同的操作。

I predict that your external drive is formatted 32 and that the filenames you're writing to it are somewhere around 45 characters long. 我预计您的外部驱动器的格式为32,并且您要写入的文件名长度约为45个字符。

FAT32 can only have 65536 directory entries in a directory. FAT32在一个目录中只能有65536个目录条目。 Long file names use multiple directory entries each. 长文件名每个都使用多个目录条目。 And "." 并且“。” always takes up one entry. 总是占用一个条目。 That you are able to write 65536/5 - 1 = 13106 entries strongly suggests that your filenames take up 5 entries each and that you have a FAT32 filesystem. 您能够写入65536/5-1 = 13106个条目,强烈表明您的文件名每个都占用5个条目,并且您具有FAT32文件系统。 This is because there exists code using 16-bit numbers as directory entry offsets. 这是因为存在使用16位数字作为目录条目偏移量的代码。

Additionally, you do not want to search through multi-1000 entry directories in FAT -- the search is linear. 此外,你不想在FAT通过多1000进入目录搜索-搜索是线性的。 Ie fopen(some_file) will induce the OS to march linearly through the list of files, from the beginning every time, until it finds some_file or marches off the end of the list. 即,fopen(some_file)会导致操作系统从每次开始一直线性浏览文件列表,直到找到some_file或从列表末尾开始。

Short answer: Directories are a good thing. 简短答案:目录是一件好事。

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

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