Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: How to test if "MD C:\A\B\C\D\E\F" will succeed - WITHOUT executing it.  (Read 2887 times)

0 Members and 1 Guest are viewing this topic.

ALAN_BR

    Topic Starter


    Hopeful

    Thanked: 5
    • Computer: Specs
    • Experience: Experienced
    • OS: Windows 7
    I am bullet proofing a script to supervise the removal of all traces of a security application in preparation for the clean install of an upgrade.

    I have a list of paths, each of which terminates with a list of folders and files to be removed.  That is no problem - job done ! !

    Unfortunately when all traces are removed the upgrade will FAIL if any folder/file is not removed because it cannot be seen because of a lack of access to any portion of the path.

    I can easily try "MD C:\A\B\C\D\E\F" to test whether there may be permission issues to prevent a clean install.  This would be a nice bonus if I can "throw it in free".
    Unfortunately if "MD C:\A\B\C\D\E\F" is successful then I ought to "do no harm" and restore the previous status quo.
    "RD C:\A\B\C\D\E\F" only removes the "\F" tail, whilst MD could have appended "\D\E\F".
    Various people with various XP/VISTA/etc have listed various paths and items that need purging - hardly a %USERPROFILE% in any of them.
    If MD has created relevant paths for both XP and VISTA, then after the RD there will be almost complete VISTA paths extra on XP, and almost complete XP paths extra on VISTA.

    I therefore wish to predict whether it is possible to create a specific path before it is done.

    CACLS gives me some clues about some access restrictions, and other numbers apply to both creatable and UNcreatable folders.
    CACLS "C:\A\B\C\D\E\F" gives the following results :-
    %ERRORLEVEL% = 2 when "F" does not exist - MD will make it;
    %ERRORLEVEL% = 3 when "E\F" do not exist - MD will make it;
    %ERRORLEVEL% = 267 if "F" cannot exist when "E" is a file, MD will never correct that;
    %ERRORLEVEL% = 3 if "E\F" cannot exist when "D" is a file, MD will never correct that;
    %ERRORLEVEL% = 5 if "E" is different user profile with no access, MD will never correct that;
    %ERRORLEVEL% = 3 if "D" is a folder with no access, MD will never correct that;

    Has anyone any ideas about SIMPLE alternative tests.
    This is only a "FREE BONUS" that I do NOT need to include in an un-install script,
    and I am not prepared at this stage to parse the path into individual folders and test the accessibility of each folder for a permissions blockage.

    I have more than enough complexity with REG.EXE telling me all sorts of lies when I try to delete a key -
    with one breath it tells me on the console stream success because the key exists,
    and with the same breath on the error console it tells me of sub-keys which are access denied,
    whilst %ERRORLEVEL% == 0 whenever the console stream says anything and it ignores the error stream.

    regards
    Alan
    « Last Edit: July 05, 2010, 02:34:56 PM by ALAN_BR »

    Salmon Trout

    • Guest
    surely RD /S C:\A will remove the whole tree?

    ALAN_BR

      Topic Starter


      Hopeful

      Thanked: 5
      • Computer: Specs
      • Experience: Experienced
      • OS: Windows 7
      Agreed, but that is not what I want.

      There are very many paths to be dealt with, here are two of them.

      For my Win XP I need to deal with application folders held under
      "%systemdrive%\Documents and Settings\%username%\L*\Application Data\..."
      For another P.C. with W7  the same application folders are held under
      "%systemdrive%\Users\%username%\L*\Application Data\

      To my script I have recently added the paths for W7,
      and absolutely no harm is done when I delete appropriate files after
      CALL :SET_CD "%NEXT_PATH%"
      because that will use
      CD /D "%NEXT_PATH%"
      and if "%NEXT_PATH%" does not exist it will then take action to avoid deletion of the existing current directory.
      No harm is done even when a W7 path is used on an XP machine, and vice-versa.

      For my BONUS feature I tried "MD %PATH%" cancelled by "RD %PATH%"
      This perfectly removes the very last folder on the designated path,
      but if the last 3 folders did not exist before "MD %PATH%" I leave behind a couple of extras.
      And if this is a W7 path on an XP machine it will be left with a complete redundant W7 path I never had before, and vice-versa.

      With a small bit of code I can parse the contents of %PATH% and then remove the whole tree with
      RD /S C:\A
      That will perfectly remove from XP the W7 path starting at  %systemdrive%\Users\
      But it would be bad news for a W7 system to have that path wiped out.
      So I would need to classify each path that is specific to either XP or W7,
      and at "run time" the O.S. must be determined and the "wrong" paths bypassed.

      I am sure I can do that, and though I "never make mistakes" I always test my code to be sure - but I have no W7 to test on so I will not release code that may endanger the health of other people's computers.

      I can use %USERPROFILE% to cover both the examples above and avoid all such problems.
      Unfortunately there are many other paths that are to be dealt with, and for some there is no convenient environmental variable that will deal with either version.

      My BONUS feature is not worth all the extra code and testing, nor is it worth putting at risk VISTA and W7 machines - but they should have remained faithful to XP ! ! !

      Hence I am looking for a simple solution that does not involve writing and deleting folders.

      Regards
      Alan