No announcement yet.

Folder Name As

  • Filter
  • Time
  • Show
Clear All
new posts

  • Folder Name As

    I tried something like this and got an Error 70 - Permission Denied.

    Name "FolderA" As "FolderB"
    FolderA existed, FolderB did not exist.

    The Close statement would close any open file that might contribute to the Error.

    But other than an open file within FolderA, what else might cause such an error?

    Help for NameAs does not specifically mention what would cause Error 70.

    Help for Error 70 says this, but none of that seems to apply. I can create file in FolderA, so it does not seem to be write-protected.

    Permission denied - (%ERR_PERMISSIONDENIED) - You tried to write to a write-protected disk. This error can also be generated as a result of network permission errors, such as accessing a locked file, or a locked record. It can also occur when attempting to open a subdirectory as a file.
    It's rare that I change folder names and have not run into this problem before. Mostly I rename files.

  • #2
    I created a small test app that has nothing in it but the Name As code. It successfully changes the folder name.

    But in my larger app, the Name As code consistently gives the Error 70. So it would seem that my app is doing something that results in an Error when NameAs is used.

    I'm not sure what that might be, so I'm just trying things out to see if something unexpected is causing the problem - removing leading code lines a few at a time to home in on the code that might be the culprit.


    • #3
      A few immdeiate thoughts:
      What is the current directory?
      Where is FolderA?
      Do you have an open DIR$ handle (see DIR$ CLOSE)


      • #4
        Howdy, Stuart!

        Thanks for responding!

        Per your suggestions, I modified my app to this and still get the error.

        ChDir$ Exe.Path$
        Dir$ Close
        Name "gallery\animals" As "gallery\butter"
        The folder "gallery" is in EXE.Path$. The folder "animals" is an existing subfolder of "gallery" I use IsFolder to verify that "gallery\animals" exists. The folder "butter" does not exist.

        I haven't yet been able to create a stand-alone code that demonstrates the problem. That usually helps me get to the offending code.


        • #5
          Is "\animals" also in Path$ ? (which would amount to renaming the current directory)


          • #6
            Did you try running your programs "run as administrator"
            where is your program, is it in a restricted folder?


            • #7
              Perhaps you have to be in the target folder's parent directory. Not tested.
              Also, do you have any open files in the folder to be renamed?
              In some future era, dark matter and dark energy will only be found in Astronomy's Dark Ages.


              • #8
                Howdy, Dale!
                No, animals is not in Path$

                Howdy, Rod!
                The Exe.Path$ is not in a restricted folder. And yes, I tried running as admin and that failed as well.

                Howdy, Rodney!
                By test with other code, I've shown that I dot not have to be in the target folder's parent directory. And no, the "Close" statement ensures that there are no open files in the folder to be renamed.

                I'm still trying to extract just the problem code from the larger app , that demos the problem.


                • #9
                  Could it have something to do with write caching? Maybe whatever you had open before the rename is closed in your mind but isn't truly closed as far as the operating system is concerned.


                  • #10
                    Howdy, Frank!

                    Thanks for the thought. I just went and inserted a 2s Sleep before the NameAs code. The error still occurs, just 2s later!


                    • #11
                      Gary, methinks it's time for #DEBUG DISPLAY ON with a sidekick label to move appropriately. Might be quicker than us guessing.
                      In some future era, dark matter and dark energy will only be found in Astronomy's Dark Ages.


                      • #12
                        Obviously, an Error 70 is your IDE talking to you. This may sound barmy, but just do a compile and then close your IDE. Now try to execute the exe and see if Windows has anything to say.


                        • #13
                          I see I forgot to suggest commenting out the offending line and compiling with #DEBUG DISPLAY ON.
                          In some future era, dark matter and dark energy will only be found in Astronomy's Dark Ages.


                          • #14
                            I've got to get a compilable example that demonstrates the failure. I'm out of the office a good part of the day but will work on it when I can.

                            Thanks, everyone, for your suggestions. As Rodney says I need to give you (and me) a way to avoid guessing.


                            • #15
                              > The folder "gallery" is in EXE.Path$

                              EXE.Path$ is not always = CURDIR$. Try using fully explicit path names.
                              "Not my circus, not my monkeys."


                              • #16
                                Howdy, Eric!

                                Thanks for the suggestion. I tried adding Exe.Path$ to the folder names and I still get the failure.

                                I also verified that CurDir$ = Exe.Path$.


                                • #17
                                  As anything open in the folder? i.e., you are running the EXE from it? some file open in Notepad? Is virus scanner perhaps holding a file open?

                                  Any open file in the folder or sub-folders will prevent a rename.

                                  I'll also reiterate Rod's statement about restricted folder/admin rights.
                                  <b>George W. Bleck</b>
                                  <img src=''>


                                  • #18
                                    Howdy, George!

                                    Yes, I thought about that but I have not used "Open" on any of the files (images) in the folder.

                                    BUT, what I did use was GDIP API to load the images. In particular, this function was used in the Image Gallery code that I posted a couple of days ago:

                                    Sub GalleryLoadSoloFromFile(fName$)
                                       'load JPG/GIF/PNG image to memory bitmap from file
                                       GdipLoadImageFromFile((fName$), pImage)  'pImage - image object
                                       GdipGetImageWidth(pImage,wSolo)          'get width
                                       GdipGetImageHeight(pImage,hSolo)         'get height
                                       'get rid of existing hBMPSolo Memory Bitmap
                                       If hBMPSolo Then
                                          Graphic Attach hBMPSolo, 0
                                          Graphic Bitmap End : hBMPSolo = 0
                                       End If
                                       'create memory bitmap for holding the image
                                       Graphic Bitmap New wSolo,hSolo To hBMPSolo
                                       Graphic Attach hBMPSolo,0
                                       Graphic Get DC To hDCSolo                                 'hDC is for memory bitmap
                                       GdipCreateFromHDC(hDCSolo, pGraphics)                     'create graphic object
                                       GdipDrawImageRect(pGraphics, pImage, 0,0,wSolo,hSolo)     'draw image at 0,0
                                       Graphic Attach hDlg, %IDC_Graphic, ReDraw
                                    End Sub
                                    I put these next two lines of GDIP cleanup code in Image Gallery under WM_Destroy, to run when the app closed.

                                    GdipDisposeImage(pImage) 'GDIP cleanup
                                    GdipDeleteGraphics(pGraphics) 'GDIP cleanup
                                    But in a quick test, I think adding those two lines to the GalleryLoadSoloFromFile function is necessary. Give me a couple more minutes to confirm that is the fix.

                                    If so, I mistakenly thought the two lines of code were end-of-app cleanup rather than being necessary after loading each file.


                                    • #19
                                      Yep, that seems to solve the problem.

                                      I've used the function above (without the two lines) many times and had never seen a problem. As Paul said in another thread, I was just "lucky" that I did not use code that the missing lines would cause to fail. The success to date with that function made me think using the two lines at end-of-app was appropriate, when it now seems that is not the case.

                                      I still need to go read about the cleanup code. There may yet be another nuance I've not gotten right!


                                      • #20
                                        Heck, that took way too much time. Thanks again for all of your suggestions.

                                        Here's an interesting quote I just found on MSDN ...

                                        Whenever you make calls to GDI+, you should do so by calling the methods and functions provided by the C++ wrappers. Microsoft Product Support Services will not provide support for code that calls the flat API directly
                                        I don't know if that hurts my feelings or not? If we use flat API we are second-class customers? Pooh on that!