I'm trying to run a Rake task on my computer running Windows but I'm having problem with the file paths. The rakefile was originally written by a user running Mac and OSX.
def compile
`cp -r app/assets/images dist/`
...
end
Running the task above gives me an error: Errno::ENOENT: No such file or directory - cp -r app/assets/images dist/
The folders are there and the following command works in the terminal:
cp -r .\app\assets\images dist\
However, changing the command in the rake file to the following doesn't work:
`cp -r .\\app\\assets\\images dist\\`
Is there some way to run the original rakefile on my Windows machine? That would be the best. If that's not possible, how can I update the rakefile to make it work?
You'll have to modify the Rakefile. Main issue is that cp
is an UNIX command and Windows uses copy
/ xcopy
. I'm not a Windows expert, but I believe xcopy /E
is for recursive copy.
I believe you can verify that Ruby will validate files paths by running:
RUBY_PLATFORM
# => "x64-mingw32" I'm on Windows too :(
File.exists? File.join('app', 'views', 'submissions.erb')
# => true
File.exists? 'app/views/submissions.erb'
# => true
File.exists? 'app\views\submissions.erb'
# => true
File.exists? 'app\\views\\submissions.erb'
# => true
The best solution IMO is to use FileUtils:
require 'fileutils'
FileUtils.cp_r('app/assets/images', 'dist/')