Help with DIR command & Registry

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rbgh
    PCHF Member
    • Mar 2020
    • 15

    #1

    Help with DIR command & Registry

    Hi
    I made cascade context menu to create list of files but there’s some issues and questions
    1. Why both 2 options that include subfolders make empty list?
      Batch files work when I run them manually by double clicking.
    2. What exactly %1 does in batch files?
      I removed them and there was no difference.
    3. How can I type multiple lines in command/default key so I will be able to add ron this commands without batch files?
  • Bruce
    PCHF Moderator
    • Oct 2017
    • 10697

    #2
    %1 is for passing variables to a script.
    so %1 is the first variable passed, %2 the second, and so on.

    if you posted your script, we’ll be able to help more.

    Comment

    • rbgh
      PCHF Member
      • Mar 2020
      • 15

      #3
      Originally posted by Bruce
      %1 is for passing variables to a script.
      so %1 is the first variable passed, %2 the second, and so on.

      if you posted your script, we’ll be able to help more.
      Admins delete files I don’t no why but if they tell me the reason I will upload them again but let me type them

      Comment

      • rbgh
        PCHF Member
        • Mar 2020
        • 15

        #4
        There are 4 batch files in β€œC:\Windows\System32” as follows:

        Copy File List (Include Subfolders).bat
        {
        chcp 65001
        @echo off
        dir %1 /b /s /a /o:gn | clip
        }

        Copy File List.bat
        {
        chcp 65001
        @echo off
        dir %1 /b /a /o:gn | clip
        }

        Create File List (Include Subfolders).bat
        {
        chcp 65001
        @echo off
        dir %1 /b /s /a /o:gn > β€œ%temp%\fileList.txt”
        start notepad β€œ%temp%\fileList.txt”
        }

        Create File List.bat
        {
        chcp 65001
        @echo off
        dir %1 /b /a /o:gn > β€œ%temp%\fileList.txt”
        start notepad β€œ%temp%\fileList.txt”
        }

        And the Registry file

        Attached file removed security reasons

        Comment

        • rbgh
          PCHF Member
          • Mar 2020
          • 15

          #5
          Originally posted by Bruce
          %1 is for passing variables to a script
          So there won’t be any difference whether include %1 or not?

          Comment

          • rbgh
            PCHF Member
            • Mar 2020
            • 15

            #6
            Originally posted by rbgh
            Attached file removed security reasons
            The Registry file:
            File List.reg
            {
            Windows Registry Editor Version 5.00

            [HKEY_CLASSES_ROOT\Directory\shell\File List]
            β€œSubCommands”=β€œβ€
            β€œExtended”=β€œβ€

            [HKEY_CLASSES_ROOT\Directory\shell\File List\shell]

            [HKEY_CLASSES_ROOT\Directory\shell\File List\shell\1Create File List]
            β€œMUIVerb”=β€œCreate File List”

            [HKEY_CLASSES_ROOT\Directory\shell\File List\shell\1Create File List\command]
            @=β€œC:\Windows\System32\Create File List.bat "%1"”

            [HKEY_CLASSES_ROOT\Directory\shell\File List\shell\2Create File List (Include Subfolders)]
            β€œMUIVerb”=β€œCreate File List (Include Subfolders)”

            [HKEY_CLASSES_ROOT\Directory\shell\File List\shell\2Create File List (Include Subfolders)\command]
            @=β€œC:\Windows\System32\Create File List (Include Subfolders).bat "%1"”

            [HKEY_CLASSES_ROOT\Directory\shell\File List\shell\3Copy File List]
            β€œMUIVerb”=β€œCopy File List”
            β€œCommandFlags”=dword:00000020

            [HKEY_CLASSES_ROOT\Directory\shell\File List\shell\3Copy File List\command]
            @=β€œC:\Windows\System32\Copy File List.bat "%1"”

            [HKEY_CLASSES_ROOT\Directory\shell\File List\shell\4Copy File List (Include Subfolders)]
            β€œMUIVerb”=β€œCopy File List (Include Subfolders)”

            [HKEY_CLASSES_ROOT\Directory\shell\File List\shell\4Copy File List (Include Subfolders)\command]
            @=β€œC:\Windows\System32\Copy File List (Include Subfolders).bat "%1"”

            [HKEY_CLASSES_ROOT\Directory\background\shell\File List]
            β€œSubCommands”=β€œβ€
            β€œExtended”=β€œβ€

            [HKEY_CLASSES_ROOT\Directory\background\shell\File List\shell]

            [HKEY_CLASSES_ROOT\Directory\background\shell\File List\shell\1Create File List]
            β€œMUIVerb”=β€œCreate File List”

            [HKEY_CLASSES_ROOT\Directory\background\shell\File List\shell\1Create File List\command]
            @=β€œC:\Windows\System32\Create File List.bat”

            [HKEY_CLASSES_ROOT\Directory\background\shell\File List\shell\2Create File List (Include Subfolders)]
            β€œMUIVerb”=β€œCreate File List (Include Subfolders)”

            [HKEY_CLASSES_ROOT\Directory\background\shell\File List\shell\2Create File List (Include Subfolders)\command]
            @=β€œC:\Windows\System32\Create File List (Include Subfolders).bat”

            [HKEY_CLASSES_ROOT\Directory\background\shell\File List\shell\3Copy File List]
            β€œMUIVerb”=β€œCopy File List”
            β€œCommandFlags”=dword:00000020

            [HKEY_CLASSES_ROOT\Directory\background\shell\File List\shell\3Copy File List\command]
            @=β€œC:\Windows\System32\Copy File List.bat”

            [HKEY_CLASSES_ROOT\Directory\background\shell\File List\shell\4Copy File List (Include Subfolders)]
            β€œMUIVerb”=β€œCopy File List (Include Subfolders)”

            [HKEY_CLASSES_ROOT\Directory\background\shell\File List\shell\4Copy File List (Include Subfolders)\command]
            @=β€œC:\Windows\System32\Copy File List (Include Subfolders).bat”

            }

            What is the security reason?

            Comment

            • Bruce
              PCHF Moderator
              • Oct 2017
              • 10697

              #7
              Security reasson is REG and BAT files can cause malicious behaviour.

              when you start your batch files, if you aren’t passing a parameter to it, then %1 means nothing, therefore the command dir %1 would get the files from the current directory, and because you have the bat file in the \system32 folder, you will get those files.

              so I have to ask, why are you putting four BAT files in the system folder and why are you hacking the registry?

              Comment

              • rbgh
                PCHF Member
                • Mar 2020
                • 15

                #8
                Originally posted by Bruce
                so I have to ask, why are you putting four BAT files in the system folder and why are you hacking the registry?
                System folder is my chosen directory, doesn’t matter where BAT files are stored.

                I add these commands because I need files list frequently and it’s much easier to have the option in context menu.
                And as I said if anyone can help me to write multiple lines in string value there would be no need to batch files at all. (It’s not possible to write multiple lines in string edit gui panel and haven’t test to write them down in .reg file and then try to import it.)

                At first there was no BAT file and the Registry file was like this:
                {
                Windows Registry Editor Version 5.00

                [HKEY_CLASSES_ROOT\Directory\background\shell\Copy File List]
                β€œExtended”=β€œβ€

                [HKEY_CLASSES_ROOT\Directory\background\shell\Copy File List\command]
                @=β€œcmd /c dir /b /s /a /o:gn | clip”

                [HKEY_CLASSES_ROOT\Directory\shell\Copy File List]
                β€œExtended”=β€œβ€

                [HKEY_CLASSES_ROOT\Directory\shell\Copy File List\command]
                @=β€œcmd /c dir "%1" /b /s /a / o:gn | clip”
                }

                But there was some problem with file’s name containing unicode characters.
                Originally posted by Bruce
                Security reasson is REG and BAT files can cause malicious behaviour.
                So why users are able to upload Registry files? I knew that BAT files are not allowed and I just typed them
                Anyway…

                Comment

                • Bruce
                  PCHF Moderator
                  • Oct 2017
                  • 10697

                  #9
                  Let’s back up a moment here, what is it you are trying to get the BAT file to do?

                  your first one lists all files in the \system32 folder (since you aren’t passing the script any parameters) and pipes the output to the clipboard.
                  The second does the same but without sub folders.
                  the third, same as first but now the output gets directed to a text file and then opened in notepad.
                  the fourth, same as third but without sub folders.

                  what is the file list used for, and do you only want it to list that system folder?

                  Comment

                  • rbgh
                    PCHF Member
                    • Mar 2020
                    • 15

                    #10
                    No I want it to list every folder that I right click on and the 1st & 3rd are working but 2 other option returns empty list with using batch files.

                    I could get rid of batch files & everything is working fine.
                    But if anybody can improve this method I appreciate it.

                    Here is the Registry file

                    {
                    Windows Registry Editor Version 5.00

                    [HKEY_CLASSES_ROOT\Directory\shell\File List]
                    β€œSubCommands”=β€œβ€
                    β€œExtended”=β€œβ€

                    [HKEY_CLASSES_ROOT\Directory\shell\File List\shell]

                    [HKEY_CLASSES_ROOT\Directory\shell\File List\shell\1Create File List]
                    β€œMUIVerb”=β€œCreate File List”

                    [HKEY_CLASSES_ROOT\Directory\shell\File List\shell\1Create File List\command]
                    @=β€œcmd /u /c dir "%1" /b /a /o:gn > C:\Windows\Temp\fileList.txt && start notepad C:\Windows\Temp\fileList.txt”

                    [HKEY_CLASSES_ROOT\Directory\shell\File List\shell\2Create File List (Include Subfolders)]
                    β€œMUIVerb”=β€œCreate File List (Include Subfolders)”

                    [HKEY_CLASSES_ROOT\Directory\shell\File List\shell\2Create File List (Include Subfolders)\command]
                    @=β€œcmd /u /c dir "%1" /b /s /a /o:gn > C:\Windows\Temp\fileList.txt && start notepad C:\Windows\Temp\fileList.txt”

                    [HKEY_CLASSES_ROOT\Directory\shell\File List\shell\3Copy File List]
                    β€œMUIVerb”=β€œCopy File List”
                    β€œCommandFlags”=dword:00000020

                    [HKEY_CLASSES_ROOT\Directory\shell\File List\shell\3Copy File List\command]
                    @=β€œcmd /c chcp 65001 && dir "%1" /b /a /o:gn | clip”

                    [HKEY_CLASSES_ROOT\Directory\shell\File List\shell\4Copy File List (Include Subfolders)]
                    β€œMUIVerb”=β€œCopy File List (Include Subfolders)”

                    [HKEY_CLASSES_ROOT\Directory\shell\File List\shell\4Copy File List (Include Subfolders)\command]
                    @=β€œcmd /c chcp 65001 && dir "%1" /b /s /a /o:gn | clip”

                    [HKEY_CLASSES_ROOT\Directory\background\shell\File List]
                    β€œSubCommands”=β€œβ€
                    β€œExtended”=β€œβ€

                    [HKEY_CLASSES_ROOT\Directory\background\shell\File List\shell]

                    [HKEY_CLASSES_ROOT\Directory\background\shell\File List\shell\1Create File List]
                    β€œMUIVerb”=β€œCreate File List”

                    [HKEY_CLASSES_ROOT\Directory\background\shell\File List\shell\1Create File List\command]
                    @=β€œcmd /u /c dir /b /a /o:gn > C:\Windows\Temp\fileList.txt && start notepad C:\Windows\Temp\fileList.txt”

                    [HKEY_CLASSES_ROOT\Directory\background\shell\File List\shell\2Create File List (Include Subfolders)]
                    β€œMUIVerb”=β€œCreate File List (Include Subfolders)”

                    [HKEY_CLASSES_ROOT\Directory\background\shell\File List\shell\2Create File List (Include Subfolders)\command]
                    @=β€œcmd /u /c dir /b /s /a /o:gn > C:\Windows\Temp\fileList.txt && start notepad C:\Windows\Temp\fileList.txt”

                    [HKEY_CLASSES_ROOT\Directory\background\shell\File List\shell\3Copy File List]
                    β€œMUIVerb”=β€œCopy File List”
                    β€œCommandFlags”=dword:00000020

                    [HKEY_CLASSES_ROOT\Directory\background\shell\File List\shell\3Copy File List\command]
                    @=β€œcmd /c chcp 65001 && dir /b /a /o:gn | clip”

                    [HKEY_CLASSES_ROOT\Directory\background\shell\File List\shell\4Copy File List (Include Subfolders)]
                    β€œMUIVerb”=β€œCopy File List (Include Subfolders)”

                    [HKEY_CLASSES_ROOT\Directory\background\shell\File List\shell\4Copy File List (Include Subfolders)\command]
                    @=β€œcmd /c chcp 65001 && dir /b /s /a /o:gn | clip”
                    }

                    I don’t know why but Windows wasn’t able to create text file in %temp% so I just changed it to β€œC:\Windows\Temp”

                    Comment

                    • Bruce
                      PCHF Moderator
                      • Oct 2017
                      • 10697

                      #11
                      But why do you want to list all the files in a folder you right click on?
                      what do you then do with that list?
                      i’m wondering if there are off-the-shelf solutions that may do want you want.

                      Comment

                      • rbgh
                        PCHF Member
                        • Mar 2020
                        • 15

                        #12
                        I want lists to compare and find the duplicate or identical files between directories or even devices or just to store the list of files.

                        Comment

                        • Bruce
                          PCHF Moderator
                          • Oct 2017
                          • 10697

                          #13
                          Something like WizTree can export files to a CSV file which you can sort, looking for dups.
                          then there are File Explorer alternatives like XYplorer that does all sort of add-on goodies.

                          Comment

                          • Bruce
                            PCHF Moderator
                            • Oct 2017
                            • 10697

                            #14
                            @rbgh, do you still need help?

                            Comment

                            • rbgh
                              PCHF Member
                              • Mar 2020
                              • 15

                              #15
                              Originally posted by Bruce
                              @rbgh, do you still need help?
                              At this time no.
                              Thanks for your recommendation.

                              Comment

                              Working...