require 'FileUtils'
path = '../tmp/brpm_storage/FGRKKSSUI/lentkriskeditor/1.2.5/20170705121128/lentkriskeditor-1.2.5-dist/lentkriskeditor-1.2.5/jre/jre1.8.0_131/lib/desktop/icons/HighContrast/48x48/mimetypes/gnome-mime-application-x-java-jnlp-file.png'
FileUtils.mkdir_p(File.dirname(path))
File.open(path, 'wb') {|file|
# File.open(File.expand_path(path), 'wb') {|file| # Full path always works
file.write('Hello')
}
失败
tmp.rb:6:in `initialize': No such file or directory - ../tmp/brpm_storage/FGRKKSSUI/lentkriskeditor/1.2.5/20170705121128/lentkriskeditor-1.2.5-dist/lentkriskeditor-1.2.5/jre/jre1.8.0_131/lib/desktop/icons/HighContrast/48x48/mimetypes/gnome-mime-application-x-java-jnlp-file.png (Errno::ENOENT)
"C:/src3/branches/PSENG-5315/BMC/utils/tmp/brpm_storage/FGRKKSSUI/lentkriskeditor/1.2.5/20170705121128/lentkriskeditor-1.2.5-dist/lentkriskeditor-1.2.5/jre/jre1.8.0_131/lib/desktop/icons/HighContrast/48x48/mimetypes/gnome-mime-application-x-java-jnlp-file.png"
from C:/src3/branches/PSENG-5315/BMC/utils/yatra_logic/tmp.rb:6:in `open'
from C:/src3/branches/PSENG-5315/BMC/utils/yatra_logic/tmp.rb:6:in `<top (required)>'
from -e:1:in `load'
from -e:1:in `<main>'
我在ruby 1.9.3 v551和2.0.0中注意到了这种现象。使用JRuby,一切都按预期工作。我想知道罪魁祸首是什么?
c:\Ruby200\bin\ruby.exe -v
ruby 2.0.0p0 (2013-02-24) [i386-mingw32]
答案 0 :(得分:1)
请参阅Why does the 260 character path length limit exist in Windows?和https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx
某些Windows API的文件路径字符串长度限制为260个字符。 (我假设它指的是Windows CP-1252字符。)
我怀疑JRuby通过JVM导航文件路径,这可以解决这个限制。见How does Java circumvent the windows MAX_PATH WinAPI limitation。