2

I have a large log file located on a network drive that is being constantly written to. How can I copy it through code without locking it?

    Try
        Microsoft.VisualBasic.FileSystem.FileCopy("sourcefile", "destinationfile")
    Catch ex As Exception
        ' Handle Error
    End Try

The code above, unfortunately does not work well, because while its copying the file, nothing can be written to that file.

Edit 1: It was suggested to read the content of the file and write it to the output. I would prefer not to do this, because the file is several gigabytes. I reserve this option only as a last resort, only if there is no other way to copy the file without locking it and without readying the content.

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
George
  • 2,165
  • 2
  • 22
  • 34

2 Answers2

0

how about using FileOpen in shared mode and reading and writing the output file yourself

FileOpen(1, "SourceFile", OpenMode.Input, OpenAccess.Default, OpenShare.Shared) // open destination file here read and while not at end of sourcefile read it // and write blocks out to destinatioon file. FileClose(1)

user2903089
  • 293
  • 1
  • 10
  • I would prefer not to do it. The file is several gigabytes large. I'd rather not read the content of it just for copying purposes if possible. – George Feb 12 '15 at 16:15
0

If you can't copy the file to work on it, or don't want to open the file in shared mode and then copy it that way, then another option is to have the system that generates the log file generate a series of smaller log files. Maybe one per unit, or production run, or hour, or day, or some other arbitrary break point.

cometbill
  • 1,619
  • 7
  • 19
  • 41
  • The log files are already broken down on a per-day basis. Unfortunately, this cannot be broken down further, because it is our product's core functionality. – George Mar 07 '16 at 21:44
  • Your daily logs are GB's of data? Wow. You're screwed. – cometbill Mar 08 '16 at 07:30