# Problem when copying files somehow related to REXML

**URL:** <https://www.ruby-forum.com/t/problem-when-copying-files-somehow-related-to-rexml/172495>\
**Category:** Rails\
**Created:** [July 22, 2009, 12:28pm UTC](https://www.ruby-forum.com/t/problem-when-copying-files-somehow-related-to-rexml/172495 "2009-07-22T12:28:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Javier\_Q](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/34f0e0/32.png) [@Javier\_Q](https://www.ruby-forum.com/u/Javier_Q)\
**Post date:** [July 22, 2009, 12:28pm UTC](https://www.ruby-forum.com/t/problem-when-copying-files-somehow-related-to-rexml/172495/1 "2009-07-22T12:28:34Z")

</div>

Hi guys.  
I am trying to copy files from one folder to another.  
The code is quite simple:

```
  frompath = File.join(fromdirectory,filename)
  topath = File.join(todirectory,filename)
  FileUtils.cp(frompath, topath)

```

The code actually works and indeed copies the images.  
The problem is that right after copying them, the REXML throws the  
following exception:

REXML::ParseException  
log:  
#\<RuntimeError: Illegal character ‘&’ in raw string  
"ï¿½ï¿½ï¿½ï¿½ JFIF ï¿½ï¿½;CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), quality =  
85  
ï¿½ï¿½C  
! “$” $ ï¿½ï¿½C  
ï¿½ï¿½ ï¿½  
\ " ï¿½ï¿½  
ï¿½ï¿½ï¿½ } !1A Qa "q 2ï¿½ï¿½ï¿½ #Bï¿½ï¿½ Rï¿½ï¿½$3brï¿½  
%&’()  
\*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyzï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½  
…

So., what does REXML have to do with the code?  
The actual filename comes from a parsed element. The code previous to  
the copy does something like t his.

doc = REXML::Document.new(screencontent)  
doc.root.each\_recursive {|c|  
if c.name == ‘File’  
images \<\< c.attributes[‘source’]

After that, I loop through the images array to get and copy all of the  
image files.  
I must insist that before throwing the exception, the files are  
actually copied.

Thanks so much for your help in advance.

---

<div class="post-metadata">

**Author:** ![Javier\_Q](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/34f0e0/32.png) [@Javier\_Q](https://www.ruby-forum.com/u/Javier_Q)\
**Post date:** [July 22, 2009, 1:12pm UTC](https://www.ruby-forum.com/t/problem-when-copying-files-somehow-related-to-rexml/172495/2 "2009-07-22T13:12:24Z")

</div>

On Jul 22, 10:39 am, Javier Q. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> After that, I loop through the images array to get and copy all of the  
> image files.  
> I must insist that before throwing the exception, the files are  
> actually copied.

Could you show the entire code - it’s hard to say much from the  
fragments you’ve posted.

Fred

---

<div class="post-metadata">

**Author:** ![Javier\_Q](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/34f0e0/32.png) [@Javier\_Q](https://www.ruby-forum.com/u/Javier_Q)\
**Post date:** [July 22, 2009, 5:52pm UTC](https://www.ruby-forum.com/t/problem-when-copying-files-somehow-related-to-rexml/172495/3 "2009-07-22T17:52:04Z")

</div>

We had faced same type of problem while working on [www.scrumpad.com](http://www.scrumpad.com) ,  
next generation scrum project management tool. In that case we have  
installed a gem rexml fix. that had saved us from this problem you  
can check that one.

basically rexml is used for parsing

---

<div class="post-metadata">

**Author:** ![Javier\_Q](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/34f0e0/32.png) [@Javier\_Q](https://www.ruby-forum.com/u/Javier_Q)\
**Post date:** [July 22, 2009, 11:59pm UTC](https://www.ruby-forum.com/t/problem-when-copying-files-somehow-related-to-rexml/172495/4 "2009-07-22T23:59:56Z")

</div>

I found the error. It was actually my mistake. Later in the code for  
whatever reason I was actually opening and trying to parse an image  
file with REXML, so it was breaking there, not in the previous part.

Thank you so much for your useful replys.
