Copying Windows system files

Discussion in 'Ruby' started by Stuart Clarke, Apr 8, 2009.

  1. 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
    --
    Posted via http://www.ruby-forum.com/.
    Stuart Clarke, Apr 8, 2009
    #1
    1. Advertising

  2. [Note: parts of this message were removed to make it a legal post.]

    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 Clarke
    <>wrote:

    > 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
    > --
    > Posted via http://www.ruby-forum.com/.
    >
    >
    James Herdman, Apr 8, 2009
    #2
    1. Advertising

  3. 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 Herdman 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 Clarke


    --
    Posted via http://www.ruby-forum.com/.
    Stuart Clarke, Apr 8, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Waz...
    Replies:
    1
    Views:
    683
    Xander Q.
    Jul 7, 2003
  2. Replies:
    0
    Views:
    482
  3. Replies:
    2
    Views:
    426
    Larry Bates
    Jan 11, 2006
  4. SagharAyyaz
    Replies:
    1
    Views:
    478
    Jonathan Mcdougall
    May 9, 2006
  5. Shawn Mcclain
    Replies:
    0
    Views:
    177
    Shawn Mcclain
    Sep 28, 2007
Loading...

Share This Page