Announcement

Collapse
No announcement yet.

Folder Paths

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Folder Paths

    I'm trying to create a delete.folder action in the On Pre Install.

    When I do a delete.file, I can click the icon on the right and go browse to the file and it automatically adds the path.

    The delete.folder doesn't seem to have a "browse to" option and in doing these scripts I am confused about writing the path considering it shows "\\" at the beginning ("C:\\MyFolder"). The examples don't help... For example, if I want to delete a folder and the path is... C:\users\dale\desktop\MyFolder\Images\Trains

    do I enter that path as that or do I have to use "\\" instead of the "\" or what am I doing wrong? So far I can add/delete files, but can't seem to get it to delete a folder in a folder, etc.

    Thanks.

  • #2
    Here's a screen capture showing the full setup...
    http://www.siskurail.com/FolderDelete.jpg

    Dale

    Comment


    • #3
      Regarding the use of double backslashes in file paths, please read the explanations in the docs.

      If you want to delete a folder like C:\users\dale\desktop\MyFolder\Images\Trains, then you can do it this way:

      C:\users\dale\desktop\ is the Desktop folder for the Windows account "dale". The name of the folder may be dependent on the release of the operating system, so one shouldn't use a hard coded path, but a Session Variable, or get the path with Shell.GetFolder().

      MyFolder\Images\Trains is the name of the sub folders, so this part of the path can be concatenated with the desktop folder.

      Code:
      -- see [URL="http://www.mindquake.com.br/en/articles/deployment?start=1"]http://www.mindquake.com.br/en/articles/deployment[/URL]
      local sDesktopFolder = SessionVar.Expand("%DesktopFolder%");
      
      local sFolderToDelete = sDesktopFolder .. "\\MyFolder\\Images\\Trains";
      
      if Folder.DoesExist(sFolderToDelete) then
         local tContents = File.Find(sFolderToDelete, "*.*", true, true);
      	
         if (tContents == nil) then
            -- folder is empty, so it can be removed
            Folder.Delete(sFolderToDelete);
         else
            -- folder is not empty or has children, so everything below must be deleted
            Folder.DeleteTree(sFolderToDelete);
         end
      	
         -- test for error
         error = Application.GetLastError();
         if (error ~= 0) then
            Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
         else
            Dialog.Message("Info", sFolderToDelete .. " deleted.", MB_OK, MB_ICONINFORMATION);
         end
      else
         Dialog.Message("Info", "Can't delete " .. sFolderToDelete .. ", it does not exist.", MB_OK, MB_ICONINFORMATION);
      end
      There are a few things to note. If you run this code from an elevated account instead of using "As invoker", I would determine the Desktop folder with
      Code:
      local sDesktopFolder = SessionVar.Expand("%LaunchUserDesktopFolder%");
      Make sure that the option "Collect launch user information" is checked in the Build settings. I would do this to make sure that you find the logged user's desktop (the account who started the setup), not the administrator's.

      Ulrich

      Comment


      • #4
        If all of the files and folders that I want to delete are inside my %AppFolder% can't I use relative addressing?

        My AppFolder is c:\Program Files\Microsoft Games\Train Simulator

        If I want to delete the folder: c:\Program Files\Microsoft Games\Train Simulator\Routes\Killme

        Can't I use use: %AppFolder%\Routes\Killme

        Dale

        Comment


        • #5
          You can, if you expand the Session Variable as I showed, and escape the backslashes properly. What you describe is pretty common.

          Ulrich

          Comment

          Working...
          X