是否有文件的SD卡上的目录数量的限制? [英] Is there a limit for the number of files in a directory on an SD card?

查看:364
本文介绍了是否有文件的SD卡上的目录数量的限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为Android设备编写的一个项目。它会产生大量的文件,每一天。这些都是文本文件和图像。该应用程序使用数据库来引用这些文件。

该应用程序应该澄清一个很少使用(可能几天后)后这些文件,但这个过程可能会或可能无法正常工作。这是不是对这个问题的主题。

由于一个历史性的事故,该文件的组织结构是有点天真:一切都在同一目录下;一个 .hidden 目录,其中包含一个零字节 .nomedia 文件,以prevent的MediaScanner索引吧。

今天,我看到了一个错误报告:

 产生java.io.IOException:无法创建:/sdcard/.hidden/file-4200.html
  在java.io.File.createNewFile(File.java:1263)
 

关于SD卡,我看到它有大量的存储左侧,但计数

  $ CD /Volumes/NO_NAME/.hidden
$ LS |厕所-w
9058
 

删除一些文件似乎已经允许的文件创建为今天继续进行。

遗憾的是,我没有尝试触摸荷兰国际集团一个新的文件,试图重现错误在一个命令行;我也删除了几百文件而不是少数。

不过,我的问题是:

  • 有没有对文件大小或文件数量目录中的硬性限制?
  • 是我甚至在正确的轨道在这里?

诺塔贝内: SD卡是按原样 - 也就是我还没有格式化,所以我猜想那将是一个脂肪 - *格式

在FAT-32格式,拥有2GB的文件大小的硬限制(远高于我处理的filesizes),并在根目录下的文件数量的限制。我绝对不写在根目录下的文件。

解决方案

有对FAT文件系统的根目录512项的限制。此限制来约,因为根目录生活在一个特定的地方在FAT文件系统。

有关其他目录此限制不到位。此外,FAT32被处理的根目录与任何其他目录中删除了512项限制为根文件系统。

使用长文件名 - 即不是8.3格式 - 均值比单个文件使用多个目录条目 <。 / P>

有些谷歌搜索发现一些人声称一个FAT32目录中最多可有65,536个条目 (这将是较少的文件,如果他们有长文件名)。然而,这些方法都提到这个限制的来源似乎是可靠的,所以我想我会对此进行测试。

我写了30个字符的文件名的文件创建一个脚本,这意味着每一个文件都需要4目录条目。当脚本得到了文件16,384它失败,IO错误,我不能创建在我的测试directoy更多的文件。因此,这似乎验证了65,536项限制。

如果你打这个限制9,000文件,那么文件必须使用每一个对应的文件名是至少66个字符长,至少7项。这是否匹配你在做什么? (或者你可以有一些短文件名和一些很长很长的,但你的想法。)

I have a project written for Android devices. It generates a large number of files, each day. These are all text files and images. The app uses a database to reference these files.

The app is supposed to clear up these files after a little use (perhaps after a few days), but this process may or may not be working. This is not the subject of this question.

Due to a historic accident, the organization of the files are somewhat naive: everything is in the same directory; a .hidden directory which contains a zero byte .nomedia file to prevent the MediaScanner indexing it.

Today, I am seeing an error reported:

java.io.IOException: Cannot create: /sdcard/.hidden/file-4200.html
  at java.io.File.createNewFile(File.java:1263)

Regarding the sdcard, I see it has plenty of storage left, but counting

$ cd /Volumes/NO_NAME/.hidden
$ ls | wc -w
9058

Deleting a number of files seems to have allowed the file creation for today to proceed.

Regrettably, I did not try touching a new file to try and reproduce the error on a commandline; I also deleted several hundred files rather than a handful.

However, my question is:

  • are there hard limits on filesize or number of files in a directory?
  • am I even on the right track here?

Nota Bene: The SD card is as-is - i.e. I haven't formatted it, so I would guess it would be a FAT-* format.

The FAT-32 format has hard limits of filesize of 2GB (well above the filesizes I am dealing with) and a limit of number of files in the root directory. I am definitely not writing files in the root directory.

解决方案

There's a limit on 512 entries in the root directory of FAT filesystem. This limit comes about because the root directory lives in a particular place on FAT filesystems.

For other directories this limit is not in place. Additionally, FAT32 removed the 512 entry limit for the root filesystem by treating the root directory the same as any other directory.

Using long filenames - i.e. not in 8.3 format - means than a single file uses multiple directory entries.

Some Googling finds some people claiming that a FAT32 directory can have a maximum of 65,536 entries (which would be fewer files if they had long file names). However, none of the sources that mentioned this limit seemed that reliable so I thought I'd test this.

I wrote a script which creates files with 30 character filenames, meaning each file would need 4 directory entries. When the script got to file 16,384 it failed with an IO error and I couldn't create more files in my test directoy. So this does seem to validate the 65,536 entry limit.

If you're hitting this limit at 9,000 files then your files must be using at least 7 entries each which corresponds to filenames that are at least 66 characters long. Does this match what you're doing? (Or you could have some short filenames and some very, very long ones, but you get the idea.)

这篇关于是否有文件的SD卡上的目录数量的限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆