I am struggling to get an image from app's documents directory. The image is called '10 sept 202316/32/57'. And when I am trying to fetch it, I get this error:
我正在努力从APP的文档目录中获取图片。这张图片名为202316/32/57年9月10日。当我尝试获取它时,我收到以下错误:
Cannot retrieve length of file, path = '.../10 sept 202316/32/57'
It seems that Flutter considers '/10 sept 202316' and '/32' in the name of file as paths to subdirectories which is not the case. I wonder if there is a way to explain Flutter that those are actually parts of the file name?
Ffltter似乎认为文件名中的“/10 202316”和“/32”是子目录的路径,但事实并非如此。我想知道是否有一种方法可以解释Fflat,即这些实际上是文件名的一部分?
P.S: Dunno if it matters, but the image is originally saved from the same App written on Swift (which I am currently rewriting on Flutter). And in Swift original file name was '10 sept 202316:32:57, but for some reason when it's saved to app's directory all ':' are changed to '/'
附注:不知道这是否重要,但这张图片最初是从Swift上的同一个应用程序保存的(我目前正在重写Ffltter上的应用程序)。在SWIFT中,原始文件名为‘10 Sept 202316:32:57,但由于某种原因,当它保存到应用程序的目录时,所有’:‘都更改为’/‘
更多回答
Yeah, when macos 10 was introduced, one of the weird things was the symmetrical mapping between : and / in filenames, depending on which view you were using (command line, Finder, cocoa apps, X11, and so on). Best to stay away from either of those chars using macos.
是的,当MacOS10推出时,其中一个奇怪的事情是:和/in文件名之间的对称映射,这取决于您使用的视图(命令行、Finder、可可应用程序、X11等)。最好不要使用MacOS中的任何一个字符。
优秀答案推荐
I've searched a bit about this issue,
我在这个问题上搜索了一下,
Having special chars in file names is often not recommended, especially because those characters might have some unwanted side effects depending on the programming language we are using, and in the specific case of the /
character, it means different things depending on the Operating System, or environment that is running your application.
通常不建议在文件名中使用特殊字符,特别是因为这些字符可能会产生一些不必要的副作用,具体取决于我们使用的编程语言,并且在/字符的特定情况下,它的含义取决于操作系统或运行应用程序的环境。
Notice that a /
in a web application represents a subroute for the path, in Linux means it's a subdirectory, while in Windows the same char for that is the inverted bar \
, which is also used to escape reserved characters in a lot of programming languages.
请注意,在Web应用程序中,/代表路径的子路由,在Linux中意味着它是一个子目录,而在Windows中,与此相同的字符是倒置栏,在许多编程语言中,它也被用来转义保留字符。
// Comment Example:
/* Multi-line comment Example */
\n -> new line
\t -> tab space
print(" This is an \" escaped quote")
There are some recent bug-tracking issues regarding using special chars in file names for Flutter, which might or might not be related to your issue.
最近有一些错误跟踪问题,这些问题是关于在Flight的文件名中使用特殊字符的,这些问题可能与您的问题有关,也可能与您的问题无关。
If you'd like, try to escape the problematic character from the file names.
If you are using strings for the file names, try to escape the problematic chars from the file name string, by replacing /
with \/
.
如果您愿意,可以尝试从文件名中转义有问题的字符。如果您使用字符串作为文件名,请尝试通过将/替换为\/来转义文件名字符串中有问题的字符。
Looks like I found a workaround. Loop through all files in directory looking for the one containing '10 sept 202316/32/57'
看起来我找到了一个变通办法。遍历目录中的所有文件,查找包含‘10 Sept 202316/32/57’的文件
更多回答
Good advice, thank you!
好建议,谢谢!
我是一名优秀的程序员,十分优秀!