File.open 忽略路径 [英] File.open ignoring path

查看:34
本文介绍了File.open 忽略路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将文件写入特定位置.当我使用 File.read("path/to/file") 时,它会打开正确的位置,但是当我使用以下内容时,它似乎忽略了路径.

I'm trying to write a file to a specific location. When I use File.read("path/to/file") it opens the correct location but when I use the following, it seems to disregard the path.

file_name = timestamp_filename("leads.csv")
dirname = File.dirname("C:/Users/Jordan/Dropbox/list/")

CSV.open(File.join(dirname, file_name), "w") do |csv|
    csv << ["array", "array1"]
end

我从计划任务运行它,它不可避免地最终将其保存到 C:\Users\Jordan\AppData\Local\Application Data\Application Data\Application Data\Application Data\Application Data\VirtualStore\Windows\SysWOW64.似乎计划任务从 C:\Windows\system32 运行它们的任务.

I'm running this from a scheduled task and it inevitably ends up saving it to C:\Users\Jordan\AppData\Local\Application Data\Application Data\Application Data\Application Data\Application Data\VirtualStore\Windows\SysWOW64. It also appears that scheduled tasks run their tasks from C:\Windows\system32.

我如何确保这会保存到所需的路径?

How do I make sure this saves to the path desired?

推荐答案

在 Windows 中,路径分隔符是反斜杠而不是正斜杠.在某些情况下,Windows 会默默地将正斜杠转换为反斜杠,但在某些情况下,正斜杠不起作用.

In Windows, the path separator is a backslash rather than a forward slash. Under some circumstances, Windows will silently convert forward slashes to backslashes, but there are cases where forward slashes won't work.

显然,这是其中之一!

这篇关于File.open 忽略路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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