• Login
sketchucation logo sketchucation
  • Login
ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

Writing to specific lines in a File

Scheduled Pinned Locked Moved Developers' Forum
4 Posts 2 Posters 97 Views 2 Watching
Loading More Posts
  • 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.
  • C Offline
    Chris Fullmer
    last edited by 25 Aug 2011, 03:54

    Lets say I have a file with 100 lines. I would like to open that file, and insert a line before line X (lets say line 50). Is that possible without loading the whole file into an array with readlines?

    Chris

    Lately you've been tan, suspicious for the winter.
    All my Plugins I've written

    1 Reply Last reply Reply Quote 0
    • D Offline
      Dan Rathbun
      last edited by 25 Aug 2011, 05:49

      Good question... never tried it.

      You can set the current line via lineno=(), but I suspect these IO file functions (which File inherits,) are sequential files, and using puts() after setting the line, is likely to overwrite that line.

      Perhaps you may wish to look in the standard Ruby Extended libs for a Random Access File extension ??

      I'm not here much anymore.

      1 Reply Last reply Reply Quote 0
      • D Offline
        Dan Rathbun
        last edited by 25 Aug 2011, 06:00

        OH !! Chris ... didn't realize this.. there's a TempFile manager class in the standard Ruby library.

        Also there's the PStore class, which is like a file-based Hash.

        There's also a "massive" CSV class.

        I'm not here much anymore.

        1 Reply Last reply Reply Quote 0
        • C Offline
          Chris Fullmer
          last edited by 25 Aug 2011, 06:01

          Awesome Dan, thanks! I'll go look into those.

          Lately you've been tan, suspicious for the winter.
          All my Plugins I've written

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          1 / 1
          • First post
            4/4
            Last post
          Buy SketchPlus
          Buy SUbD
          Buy WrapR
          Buy eBook
          Buy Modelur
          Buy Vertex Tools
          Buy SketchCuisine
          Buy FormFonts

          Advertisement