朱莉娅:http.download函数可以创建一个目录,而不是存在吗?
此代码失败是因为../ data/housing/
目录不存在:
function FetchHousingData(url::String, path::String)
println("FetchHousingData " * Dates.format(now(), "HH:MM:SS") )
HTTP.download(url, path)
println("done " * Dates.format(now(), "HH:MM:SS") )
end
housingUrl = "https://raw.githubusercontent.com/ageron/handson-ml2/master/datasets/housing/housing.tgz"
housingPathFile = "../data/housing/housing.tgz"
FetchHousingData(housingUrl, housingPathFile)
有没有办法让http.download()
创建一个缺少的目录?我找不到http.download
的文档。
This code failed because the ../data/housing/
directory didn't exist:
function FetchHousingData(url::String, path::String)
println("FetchHousingData " * Dates.format(now(), "HH:MM:SS") )
HTTP.download(url, path)
println("done " * Dates.format(now(), "HH:MM:SS") )
end
housingUrl = "https://raw.githubusercontent.com/ageron/handson-ml2/master/datasets/housing/housing.tgz"
housingPathFile = "../data/housing/housing.tgz"
FetchHousingData(housingUrl, housingPathFile)
Is there a way to have HTTP.download()
create a missing directory? I haven't been able to find the docs for HTTP.download
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以通过输入帮助模式从repper中获取DOCS(在REPP提示下按
?
):http.http.http.download
似乎没有Kwarg要创建目录,但您可能对isdir
:mkdir
:You can get the docs from the REPL as usual by entering help mode (press
?
at the REPL prompt):There doesn't seem to be a kwarg in
HTTP.download
to create directories, but you might be interested inisdir
:and
mkdir
:我更喜欢使用
mkPath
(在NILS显示的文档中也提到),因为它会创建父目录,并且如果目录已经存在,则不会产生错误:I prefer to use
mkpath
(also mentioned in the docs showed by Nils) as it creates parent directories and does not produce an error if the directory already exists: