# Copying Windows system files

**URL:** <https://www.ruby-forum.com/t/copying-windows-system-files/165044>\
**Category:** Ruby\
**Created:** [April 8, 2009, 4:15pm UTC](https://www.ruby-forum.com/t/copying-windows-system-files/165044 "2009-04-08T16:15:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sclarke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b19c9b/32.png) [@sclarke](https://www.ruby-forum.com/u/sclarke)\
**Post date:** [April 8, 2009, 4:15pm UTC](https://www.ruby-forum.com/t/copying-windows-system-files/165044/1 "2009-04-08T16:15:41Z")

</div>

Hi all,

Does anyone know how to copy Windows system files? I have a script which  
looks for certain files and writes a log with the path of the file found  
and copies the file found to a folder.

This works fine for all files I am interested in except the index.dat  
file. My script finds the file and writes it to a log but doesn’t  
actually copy the file. Does any one know how I can copy an index.dat  
file? The relevant code:

def copyFile(file)  
myLog = File.new(’\Test\SweeperLog.txt’, ‘a’)  
myLog.puts file  
File.copy(file, ‘\Test’)  
end

Many thanks

---

<div class="post-metadata">

**Author:** ![sclarke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b19c9b/32.png) [@sclarke](https://www.ruby-forum.com/u/sclarke)\
**Post date:** [April 8, 2009, 4:37pm UTC](https://www.ruby-forum.com/t/copying-windows-system-files/165044/2 "2009-04-08T16:37:57Z")

</div>

Hi Stuart.

Two thoughts:

1. Maybe you don’t have access to the file?

2. Instead of opening the file, reading it, and then copying it else  
where,  
why not look into using FileUtils.cp? It would be a little more direct.  
It  
also may end up being the key if you do, in fact, have access to the  
file.

James

On Wed, Apr 8, 2009 at 10:15 AM, Stuart C.

---

<div class="post-metadata">

**Author:** ![sclarke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b19c9b/32.png) [@sclarke](https://www.ruby-forum.com/u/sclarke)\
**Post date:** [April 8, 2009, 8:21pm UTC](https://www.ruby-forum.com/t/copying-windows-system-files/165044/3 "2009-04-08T20:21:41Z")

</div>

I am thinking, its being caused me copying lots of files with the same  
name (index.dat) and only the last copied file is present in my  
destination folder, which is infact corrupt.

How would I assign a new name to a file if one already exists, for  
example I am thinking

if File.exist(Index.dat)  
File.copy(file[x], ‘\Test’)  
else  
File.copy(file, ‘\Test’)

Basically I am trying to say, if you find an index.dat file in the  
destination folder copy the next index.dat file but give it a squential  
number

index[1].dat  
index[2].dat

Does that make sense?

thanks a lot

James H. wrote:

> Hi Stuart.
> 
> Two thoughts:
> 
> 1. Maybe you don’t have access to the file?
> 
> 2. Instead of opening the file, reading it, and then copying it else  
> where,  
> why not look into using FileUtils.cp? It would be a little more direct.  
> It  
> also may end up being the key if you do, in fact, have access to the  
> file.
> 
> James
> 
> On Wed, Apr 8, 2009 at 10:15 AM, Stuart C.
