No announcement yet.

Finding paths one or more levels above another one

  • Filter
  • Time
  • Show
Clear All
new posts

  • Finding paths one or more levels above another one

    Hello fellow users

    Not being a programmer, I am struggling somewhat with what should be a simple process. I hope that someone will be able to advise

    I am finding a folder path as follows...

    DestFolder = Registry.GetValue(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\ \App Paths\\Tutorials.exe", "Path", false);

    This returns a folder "C:\Program Files (x86)\MTSL\SSS\tutorials"

    This becomes my destination folder fine and I can create it no problem.

    What I want to do is go up the folder tree and create a folder "C:\Program Files (x86)\MTSL\SSS\AutoPlay"

    But I cannot find the correct syntax in command "Folder.Create"

    As I said, it's a simple problem, but I've looked through the help documentation and no attempts at using ../ and ../../ with and without quotes does the trick.

    Any assistance would be much appreciated. Thank you.


  • #2
    Try this approach:
    -- retrieve the folder of the sibling
    local sDestFolder = Registry.GetValue(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\Tutorials.exe", "Path", false);
    local sPath = String.SplitPath(sDestFolder);
    -- create the new folder
    Folder.Create(sPath.Drive .. sPath.Folder .. "..\\AutoPlay");
    error = Application.GetLastError();
    -- check result
    if (error ~= 0) then
        Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
        Dialog.Message("Info", "Folder created successfully");
    Of course the application will need to run as administrator in order to create the new folder under Program Files. This will not be required if the tutorials.exe application is deployed in the user's profile...



    • #3
      Originally posted by Nigel Lorriman View Post

      What I want to do is go up the folder tree and create a folder "C:\Program Files (x86)\MTSL\SSS\AutoPlay"
      But I cannot find the correct syntax in command "Folder.Create"

      ulrich's code works fine

      a clarification on folder.create
      use double slash and run as admin
      Folder.Create ("C:\\Program Files (x86)\\MTSL\\SSS\\AutoPlay")


      • #4
        Thank you both. I have implemented the code and run as administrator and it's creating the folder, albeit one level too high, but I'm sure I can work that out.

        I would never have got to that point without help.

        That now gives me more information to implement the file copies I am now wanting to do.


        • #5
          Would there be an obvious reason why the following Status Dialog would remain on screen when all the files have been copied?
          Click image for larger version

Name:	Untitled-1.png
Views:	79
Size:	2.0 KB
ID:	307442

          Even though I get the Dialog.Message which occurs after the copying has supposedly finished

          Click image for larger version

Name:	Untitled-2.png
Views:	80
Size:	2.1 KB
ID:	307443

          StatusDlg.Show(MB_ICONNONE, false);

          File.Copy("tutorials\\*.*", sPath.Drive .. sPath.Folder .. "\\tutorials", true, true, true, true, nil);

          StatusDlg.Hide(MB_ICONNONE, false);

          Dialog.Message("Notice", "Finished copying tutorial files.", MB_OK, MB_ICONINFORMATION);

          Especially, as there is no such file "Thumbs.db" in the source folder (hidden or otherwise).

          Basic, I know, but I can't work it out.

          Thank you.


          • #6
            Panic over. Fixed.

            Thank you anyway.