Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Working with files....

Working with files....

Scheduled Pinned Locked Moved Visual Basic
question
12 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Psycho Coder Extreme
    wrote on last edited by
    #1

    Well here I am again, heres what Im trying to to. I have a Folder Ive created in a specified path withint the application, there will be more than one file in said directory so heres what I need to do: This folder is used to hold the ErrLog.txt file I created in the application to log errors that have happened, I am now wanting to limit the size of this file to 10MB, so I need to be able to retrieve the current file being used (whether it be ErrLog1.txt, ErrLog2.txt, and so on) then check the size of this file and if its too big then close it, open a new file (with the next number appended to it) and use that file until it reaches the size limit, and so on. Ive done some searches on Google (as well as some other forums Im a member of) and havent found anything real useful, so I always return to the one place I can find answers, CP. Anyone got some ideas/links/samples I can look at and use to accomplish this?

    "Let's face it, the average computer user has the brain of a Spider Monkey." Bill Gates

    D 1 Reply Last reply
    0
    • P Psycho Coder Extreme

      Well here I am again, heres what Im trying to to. I have a Folder Ive created in a specified path withint the application, there will be more than one file in said directory so heres what I need to do: This folder is used to hold the ErrLog.txt file I created in the application to log errors that have happened, I am now wanting to limit the size of this file to 10MB, so I need to be able to retrieve the current file being used (whether it be ErrLog1.txt, ErrLog2.txt, and so on) then check the size of this file and if its too big then close it, open a new file (with the next number appended to it) and use that file until it reaches the size limit, and so on. Ive done some searches on Google (as well as some other forums Im a member of) and havent found anything real useful, so I always return to the one place I can find answers, CP. Anyone got some ideas/links/samples I can look at and use to accomplish this?

      "Let's face it, the average computer user has the brain of a Spider Monkey." Bill Gates

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      This is easy if you think about it. You don't need the log file open all the time. You open it, write your message, close it. Simple. Now, all you have to do is check the size of the file BEFORE your open the log and write to it. The FileInfo class comes in handy for that. If the size of the current logfile is greater than 10MB, increment the filename and use the new name for the log file.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007

      P 1 Reply Last reply
      0
      • D Dave Kreskowiak

        This is easy if you think about it. You don't need the log file open all the time. You open it, write your message, close it. Simple. Now, all you have to do is check the size of the file BEFORE your open the log and write to it. The FileInfo class comes in handy for that. If the size of the current logfile is greater than 10MB, increment the filename and use the new name for the log file.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007

        P Offline
        P Offline
        Psycho Coder Extreme
        wrote on last edited by
        #3

        Well I've gotten that far but am having a few issues: Figuring out what is the file currently being used (as theoretically there could be multiple files after years of use), how to determine the number at the end of the file). I already have coded to determine the size of the file. I may be over-complicating this, sometimes I do that, but I seem to have hit a wall on this.

        "Well yes, it is an Integer, but it's a metrosexual Integer. For all we know, under all that hair gel it could be a Boolean." Tom Welch

        D D 2 Replies Last reply
        0
        • P Psycho Coder Extreme

          Well I've gotten that far but am having a few issues: Figuring out what is the file currently being used (as theoretically there could be multiple files after years of use), how to determine the number at the end of the file). I already have coded to determine the size of the file. I may be over-complicating this, sometimes I do that, but I seem to have hit a wall on this.

          "Well yes, it is an Integer, but it's a metrosexual Integer. For all we know, under all that hair gel it could be a Boolean." Tom Welch

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          Psycho-*Coder*-Extreme wrote:

          Figuring out what is the file currently being used

          :confused: When you change the filename, you save it to either an XML config file you design, or your app.config file, or a spot in the registry.

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007

          P 1 Reply Last reply
          0
          • D Dave Kreskowiak

            Psycho-*Coder*-Extreme wrote:

            Figuring out what is the file currently being used

            :confused: When you change the filename, you save it to either an XML config file you design, or your app.config file, or a spot in the registry.

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                 2006, 2007

            P Offline
            P Offline
            Psycho Coder Extreme
            wrote on last edited by
            #5

            I came up with this solution:

            Private Shared Function NeedNewFile(ByVal fileName As String) As Boolean
            Dim filePath As String = sPathToUse & "\Errors\" & fileName
            If File.Exists(filePath) Then
            Dim fInfo As New FileInfo(filePath)
            Dim fileSize As Long = fInfo.Length
            With fInfo
            If .Length >= (MAX_ERRORLOG_SIZE * 1024 * 1024) Then
            File.Copy(filePath, filePath & "_Archive_" & Now.Day & Now.Month.ToString("MMM") & Now.Year & ".txt")
            Dim sWriter As New StreamWriter(filePath, False)
            sWriter.WriteLine("--New Log Created --//\\ " & Now())
            sWriter.Close()
            Return True
            Else
            Return False
            End If
            End With
            End If
            End Function

            Ad this seems to do what I need it to do (so far), now I need to do some more testing, make the target path larger than 10MB and see what happens.

            "Okay, I give up: which is NOT a real programming language????" Michael Bergman

            1 Reply Last reply
            0
            • P Psycho Coder Extreme

              Well I've gotten that far but am having a few issues: Figuring out what is the file currently being used (as theoretically there could be multiple files after years of use), how to determine the number at the end of the file). I already have coded to determine the size of the file. I may be over-complicating this, sometimes I do that, but I seem to have hit a wall on this.

              "Well yes, it is an Integer, but it's a metrosexual Integer. For all we know, under all that hair gel it could be a Boolean." Tom Welch

              D Offline
              D Offline
              Dave Sexton
              wrote on last edited by
              #6

              Psycho-*Coder*-Extreme wrote:

              there could be multiple files after years of use

              Why are you anticipating this many errors during the lifetime of the app? I have absolutely no idea about what the requirements of your project are but that doesn't sound quite right to me.

              P 1 Reply Last reply
              0
              • D Dave Sexton

                Psycho-*Coder*-Extreme wrote:

                there could be multiple files after years of use

                Why are you anticipating this many errors during the lifetime of the app? I have absolutely no idea about what the requirements of your project are but that doesn't sound quite right to me.

                P Offline
                P Offline
                Psycho Coder Extreme
                wrote on last edited by
                #7

                Dave, I'm really not anticipating that many errors from the parts that I'm responsible for, but I work with a relatively new and young programmer who has a hard time (it seems) to do adequate exception handling. Realistically there may never be more than a couple error logs over the lifespan of the application, but I have a hard time allowing myself to assume something wont happen, I have to code for exceptions to the rules as well because you never know what the users going to do, thats just the way I am.

                "Okay, I give up: which is NOT a real programming language????" Michael Bergman

                D 1 Reply Last reply
                0
                • P Psycho Coder Extreme

                  Dave, I'm really not anticipating that many errors from the parts that I'm responsible for, but I work with a relatively new and young programmer who has a hard time (it seems) to do adequate exception handling. Realistically there may never be more than a couple error logs over the lifespan of the application, but I have a hard time allowing myself to assume something wont happen, I have to code for exceptions to the rules as well because you never know what the users going to do, thats just the way I am.

                  "Okay, I give up: which is NOT a real programming language????" Michael Bergman

                  D Offline
                  D Offline
                  Dave Sexton
                  wrote on last edited by
                  #8

                  Psycho-*Coder*-Extreme wrote:

                  who has a hard time (it seems) to do adequate exception handling

                  Slap him. Slap him silly.

                  P 1 Reply Last reply
                  0
                  • D Dave Sexton

                    Psycho-*Coder*-Extreme wrote:

                    who has a hard time (it seems) to do adequate exception handling

                    Slap him. Slap him silly.

                    P Offline
                    P Offline
                    Psycho Coder Extreme
                    wrote on last edited by
                    #9

                    Dave Sexton wrote:

                    Slap him. Slap him silly.

                    I have thought about this, but I know it will cost me my job (if I knew I could get away with it I would probably do it :->. Once, he actually "bitched" at me for putting code in a Try....Catch block, saying that an error couldn't possibly happen in that function and that I needed to remove it, to which I replied "Assumptions are the mother of all f**k ups". He has a bad habit of assuming something cant happen, or that the user cant possibly do something to raise an error. No matter how hard I've tried to explain this he just wont listen, but hey in the past 4 months he's had over 20 "trouble tickets" for the processes he's coded, and I've had 2. Maybe someday he'll grow out of his arrogance and start seeing things in the right light :~

                    "Okay, I give up: which is NOT a real programming language????" Michael Bergman

                    C D 2 Replies Last reply
                    0
                    • P Psycho Coder Extreme

                      Dave Sexton wrote:

                      Slap him. Slap him silly.

                      I have thought about this, but I know it will cost me my job (if I knew I could get away with it I would probably do it :->. Once, he actually "bitched" at me for putting code in a Try....Catch block, saying that an error couldn't possibly happen in that function and that I needed to remove it, to which I replied "Assumptions are the mother of all f**k ups". He has a bad habit of assuming something cant happen, or that the user cant possibly do something to raise an error. No matter how hard I've tried to explain this he just wont listen, but hey in the past 4 months he's had over 20 "trouble tickets" for the processes he's coded, and I've had 2. Maybe someday he'll grow out of his arrogance and start seeing things in the right light :~

                      "Okay, I give up: which is NOT a real programming language????" Michael Bergman

                      C Offline
                      C Offline
                      Colin Angus Mackay
                      wrote on last edited by
                      #10

                      Psycho-*Coder*-Extreme wrote:

                      "Assumptions are the mother of all f**k ups"

                      I remember a guy on a development team I was part of yelling that at one of the sales guys who demanded a feature that we later discovered no one wanted. The sales guy just assumed that a potential customer wanted a certain feature. He didn't. And he didn't buy either.


                      Upcoming events: * Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ... * Reading: Developer Day 5 Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website

                      1 Reply Last reply
                      0
                      • P Psycho Coder Extreme

                        Dave Sexton wrote:

                        Slap him. Slap him silly.

                        I have thought about this, but I know it will cost me my job (if I knew I could get away with it I would probably do it :->. Once, he actually "bitched" at me for putting code in a Try....Catch block, saying that an error couldn't possibly happen in that function and that I needed to remove it, to which I replied "Assumptions are the mother of all f**k ups". He has a bad habit of assuming something cant happen, or that the user cant possibly do something to raise an error. No matter how hard I've tried to explain this he just wont listen, but hey in the past 4 months he's had over 20 "trouble tickets" for the processes he's coded, and I've had 2. Maybe someday he'll grow out of his arrogance and start seeing things in the right light :~

                        "Okay, I give up: which is NOT a real programming language????" Michael Bergman

                        D Offline
                        D Offline
                        Dave Kreskowiak
                        wrote on last edited by
                        #11

                        Psycho-*Coder*-Extreme wrote:

                        but hey in the past 4 months he's had over 20 "trouble tickets" for the processes he's coded, and I've had 2.

                        Is he assuming he won't get fired for his "quality" code? That's the mother of all f-ups. :-D

                        A guide to posting questions on CodeProject[^]
                        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                             2006, 2007

                        P 1 Reply Last reply
                        0
                        • D Dave Kreskowiak

                          Psycho-*Coder*-Extreme wrote:

                          but hey in the past 4 months he's had over 20 "trouble tickets" for the processes he's coded, and I've had 2.

                          Is he assuming he won't get fired for his "quality" code? That's the mother of all f-ups. :-D

                          A guide to posting questions on CodeProject[^]
                          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                               2006, 2007

                          P Offline
                          P Offline
                          Psycho Coder Extreme
                          wrote on last edited by
                          #12

                          Dave Kreskowiak wrote:

                          Is he assuming he won't get fired for his "quality" code?

                          Dave, Thats exactly what he's assuming. He's been there coming up on 4 years, and we were both made part of the IT department about 4 months ago, we were just the personal programmers for one department, we didn't have to follow any of the SOCKS(sp?) Compliance issues, none of the Software Development Life Cycle or anything, if they wanted something we made it then gave it to them, so up until now no one ever knew of any "bugs" he wrote. I'm hoping that now that they're coming to light something will be done about it.

                          "Okay, I give up: which is NOT a real programming language????" Michael Bergman

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups