Aarmora
Aarmora

Reputation: 1153

File.open ignoring path

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

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?

Upvotes: 1

Views: 91

Answers (1)

Harry Johnston
Harry Johnston

Reputation: 36308

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.

Apparently, this is one of them!

Upvotes: 2

Related Questions