Ruby FileUtils.mv invalid multibyte character - ruby

I'm use FileUtils.mv to move folder like this:
FileUtils.mv("/home/sean/_site/", "/home/sean/projects/_site/")
its returns invalid multibyte character error, the reason is the _site folder contains the following files:
?????ʼ???????????????
????fedora????ʱ??ʾcannot-open-font-file-true?İ취
?˿?????firefox????????
?ȸ?gaeӦ???̵?
??ǧ??ǧѰ???ⲿ??Ʒ???ɹ??ĵط?
but I don't know how to solve it, and when I use system command everything is ok, like this:
mv /home/sean/_site /home/sean/projects/_site
My system is ubuntu 12.04 LTS server, ruby is 2.0.0p195.
PS: On Debian system the FileUtils.mv command its ok.

Just like in bash, don't append a slash if you want to move the folder (and not its content):
FileUtils.mv("/home/sean/_site", "/home/sean/projects/_site")

Related

How can I create a file on my desktop from a Ruby script?

I'm building a webcrawler and I want it to output to a new file that is timestamped. I've completed what I thought would be the more difficult part but I cannot seem to get it to save to the desktop.
Dir.chdir "~/Desktop"
dirname = "scraper_out"
filename = "#{time}"
Dir.mkdir(dirname) unless File.exists?(dirname)
Dir.chdir(dirname)
File.new(filename, "w")
It errors out on the first line
`chdir': No such file or directory # dir_chdir - ~/Desktop
I've read the documentation on FileUtils, File and cannot seem to find where people change into nested directories from the root.
Edit: I don't think FileUtils understands the ~.
~/ is not recognized by Ruby in this context.
Try:
Dir.chdir ENV['HOME']+"/Desktop"
This might help you
Create a file in a specified directory

Is there a way to compile Pascal program and put the generated files in a specific folder?

So I am trying to compile Pascal programs and everything is find; however, I would like to put the generated files after each compilation is a separated folder. I am looking of something like this: fpc "Destination Folder" "program.pas".
Thanks
From Alphabetical listing of command line options
-FE<x> Set exe/unit output path to <x>
-FU<x> Set unit output path to <x>, overrides -FE
So something like fpc program.pas -FEc:\output should work. I don't have fpc installed so I cannot verify. If you try it and get errors that you can't work through post them.
This one works for me:
fpc hello.pas -o"Web/hello.cgi"
I was using ubuntu, notice there is no space between the argument -o and the beginning of the path "Web/..."

How can I rename a file with Ruby that includes a / character?

I've written a little Ruby command line app that I use to keep TV Shows organized on my Mac harddrive. Given the nature of TV episode titles there are episodes which include the / character.
Being on a Mac, the filesystem actually allows me writing this file and if I manually rename the file with the / character in it everything is fine.
The moment Ruby's File.rename runs in my script however I simply get a No such file or directory error because Ruby tries to read the / in the filename as a folder which should exist.
Here is an example:
Output path is /TV/Showname/Season 1/Showname - 1x07 - 5/1.mp4
Now rather than looking for the folder /Showname - 1x07 - 5/ and write to a 1.mp4 file inside of it, how can I tell ruby to simply take the filename (Showname - 1x07 - 5/1.mp4) and write it into the Season 1 folder as is?
Thanks for reading.
A weird one this, but because the backslash is used as a file-separator, it is converted to a colon in the filename used by Ruby. So to rename your file, replace the forward slash in the name with a colon.
So you would write something like:
File.rename("Showname - 1x07 - 5:1.mp4", "/TV/Showname/Season 1/Showname - 1x07 - 5:1.mp4")

Ruby: No such file or directory -- C:\Documents <LoadError>

I'm just learning Ruby and making a simple Hello World program, put for some reason the command prompt can not find the directory (which is C:\Documents and Settings\Matt\My Documents\Ruby Testing Zone\hello.rb). With the directory set to C:\Ruby193\bin, I tried to type this command to run my program:
ruby C:\Documents and Settings\Matt\My Documents\Ruby Testing Zone\hello.rb
And I end up with this error:
ruby: No such file or directory -- C:\Documents <LoadError>
I have checked many times to make sure I'm not misspelling any part of the file name. What is going on?
Put double-quotes around the whole filename. Windows won't treat it as a single parameter otherwise.
In your open command, make sure that the spaces between Documents, and, and Settings are proceded with a backslash. In other words, here's what the path should be:
C:\\Documents\ and\ Settings\\Matt\\My\ Documents\\Ruby\ Testing\ Zone\\hello.rb
Or, replace the double-backslashes with slashes:
C:/Documents\ and\ Settings/Matt/My\ Documents/Ruby\ Testing\ Zone/hello.rb

VIM+Ctags doesn't work in WinXP

Okay guys, you're my only help :)
I have GVim v. 7.3, Exuberant CTags 5.8, omnicppcomplete (0.41) - all latest, to be exact.
I'm trying to generate tags to use in VIM, but it seems to totally ignore data in tags file.
I've used ctags to generate tags file for bada framework - the file seems to be okay, class definitions present etc. I also tried to apply the same command to STL from Visual Studio.
ctags -R --c++-kinds=+p --fields=+iaS --extra=+q --language -force=C++ "c:\bada\1.0.0\Include\"
Also, I've mapped generating tags via hotkey.
map <C-F12> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .
Trying to use any of files generated by these commands did not succeed.
The command :tags shows empty tag list, but doesn't give any error, and I have no clue how to fix this.
Yes, seems that vim actually handles spaces in a weird way (Windows only?), however there are workarounds: either use dos 8.3 short names or use a wildcard instead of a space (?), like
set tags=c:\program?files?(x86)\vim\tags
PS: which tag files was successfully loaded could be checked with the
:echo tagfiles()
command
The problem was with path to tags file: c:\Program Files\Vim\bada. The VIM didn't want to parse string with spaces no matter what the slashes/backslashes used.
Reinstalling VIM to c:\VIM solved the problem.

Resources