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. C / C++ / MFC
  4. Rename a locked file

Rename a locked file

Scheduled Pinned Locked Moved C / C++ / MFC
questionadobe
4 Posts 3 Posters 1 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
    Paul Riley
    wrote on last edited by
    #1

    This seems like a really simple question, but I can't find the answer anywhere else and I know someone in here has to have faced it before. At the commandline (at least on NT/2k/XP, which is all that matters in this question), you can rename a file which is currently locked using ren and the program holding the file will adjust, allowing you to put a new file in its place ready for later. If I try to do this using MoveFileEx then (not entirely surprisingly) it complains that the file is locked. I could open a new process and use the commandline, and I will if I have to, but if there's some way of convincing MoveFileEx or call something else to rename the file then I'd prefer not to have a DOS box flash up. Does anyone know if this is possible? Paul

    D M 2 Replies Last reply
    0
    • P Paul Riley

      This seems like a really simple question, but I can't find the answer anywhere else and I know someone in here has to have faced it before. At the commandline (at least on NT/2k/XP, which is all that matters in this question), you can rename a file which is currently locked using ren and the program holding the file will adjust, allowing you to put a new file in its place ready for later. If I try to do this using MoveFileEx then (not entirely surprisingly) it complains that the file is locked. I could open a new process and use the commandline, and I will if I have to, but if there's some way of convincing MoveFileEx or call something else to rename the file then I'd prefer not to have a DOS box flash up. Does anyone know if this is possible? Paul

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Does SHFileOperation() work any better?


      "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

      1 Reply Last reply
      0
      • P Paul Riley

        This seems like a really simple question, but I can't find the answer anywhere else and I know someone in here has to have faced it before. At the commandline (at least on NT/2k/XP, which is all that matters in this question), you can rename a file which is currently locked using ren and the program holding the file will adjust, allowing you to put a new file in its place ready for later. If I try to do this using MoveFileEx then (not entirely surprisingly) it complains that the file is locked. I could open a new process and use the commandline, and I will if I have to, but if there's some way of convincing MoveFileEx or call something else to rename the file then I'd prefer not to have a DOS box flash up. Does anyone know if this is possible? Paul

        M Offline
        M Offline
        Maximilien
        wrote on last edited by
        #3

        have a look at ShFileOperation I think it works for locked files.


        Maximilien Lincourt Your Head A Splode - Strong Bad

        P 1 Reply Last reply
        0
        • M Maximilien

          have a look at ShFileOperation I think it works for locked files.


          Maximilien Lincourt Your Head A Splode - Strong Bad

          P Offline
          P Offline
          Paul Riley
          wrote on last edited by
          #4

          You guys rock, thanks. Serious brain freeze on my part. Paul

          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