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

Author Topic: batch file to find all the .exe ,mp3,msi files and list the path such file  (Read 22164 times)

0 Members and 1 Guest are viewing this topic.

Aditi gupta

    Topic Starter


    Rookie

    • Experience: Experienced
    • OS: Windows 7
    Hi,
    can someone pls help me for creating a batch file which will search all the drives on my system except C drive for all the .exe, mp3, msi extension , and will give me the path of each such file in to a notepad file or n xml file.

    suppose it first enter in D drive, then it will search for *.exe file, *.mp3 file.
    Found one file songs.mp3 , once fund, then it will display the complete path of tha songs.mp3 file.

    Same thing should be done for each such file found.

    Then it will move to E drive and will repeat the same procedure of searching .exe file, .mp3 files etc.

    please help in this regard.
    urgent.

    thanks in advance

    foxidrive



      Specialist
    • Thanked: 268
    • Experience: Experienced
    • OS: Windows 8
    Code: [Select]
    @echo off
    for %%a in (d e f g h i j k l) do if exist "%%a:\" dir /b /s /a-d "%%a:\*.exe" "%%a:\*.mp3" "%%a:\*.msi" >>"%userprofile%\desktop\results.txt"

    Aditi gupta

      Topic Starter


      Rookie

      • Experience: Experienced
      • OS: Windows 7
      thanks , for the help.

      this works for me.

      Is it possible to store this on a shared location?

      i think, we just need to change the output path with shared location.?

      foxidrive



        Specialist
      • Thanked: 268
      • Experience: Experienced
      • OS: Windows 8
      i think, we just need to change the output path with shared location.?

      Yes, that will work if you have write permission to the location.

      Aditi gupta

        Topic Starter


        Rookie

        • Experience: Experienced
        • OS: Windows 7
        is it possible that first we, discover the Os architechture , then logcal disk , and accordingly we use if and else statements .

        Input for  if , else statements would be from 1. wmic os get osarchitechture
        then
        2.wmic logicaldisk get name.


        Squashman



          Specialist
        • Thanked: 134
        • Experience: Experienced
        • OS: Other
        is it possible that first we, discover the Os architechture , then logcal disk , and accordingly we use if and else statements .

        Input for  if , else statements would be from 1. wmic os get osarchitechture
        then
        2.wmic logicaldisk get name.
        Sounds like a completely different task then your original question.

        Aditi gupta

          Topic Starter


          Rookie

          • Experience: Experienced
          • OS: Windows 7
          its not different , just we need to implememnt it using if , else.

          Suppose now i want to scan my C drive also and want to leave the Program files and windows folder.
          rest all provide me the same output.

          leaving Program fils and windows  in C drive should scan  rest of the C drive and other drives completely for .exe, .msi , .mp3 extensions.

          C:--- leave program files and windows
          D:-- full
          E:- full

          Squashman



            Specialist
          • Thanked: 134
          • Experience: Experienced
          • OS: Other
          we must be from different planets as I can not figure out how this new question has anything to do with the original.

          foxidrive



            Specialist
          • Thanked: 268
          • Experience: Experienced
          • OS: Windows 8
          Squashman, it sounds to me like a class assignment when certain commands must be used.

          Fortunately this lazy man's approach will also work to solve the question.

          Code: [Select]
          @echo off
          for %%a in (c d e f g h i j k l m n o p q r s t u v w x y z) do if exist "%%a:\" (

          dir /b /s /a-d "%%a:\*.exe" "%%a:\*.mp3" "%%a:\*.msi" |find /v /i "c:\program files\"|find /v /i "c:\windows\" >>"%userprofile%\desktop\results.txt"

          )
          pause


          Aditi gupta

            Topic Starter


            Rookie

            • Experience: Experienced
            • OS: Windows 7
            now want to store the output in shared location?

            hostname should be the name of the file

             \\<ip address>\foldername\hostname.txt

            Squashman



              Specialist
            • Thanked: 134
            • Experience: Experienced
            • OS: Other
            now want to store the output in shared location?

            hostname should be the name of the file

             \\<ip address>\foldername\hostname.txt
            Well did you at least attempt to substitute that output path with the one that is already in the code.

            Aditi gupta

              Topic Starter


              Rookie

              • Experience: Experienced
              • OS: Windows 7
              ofcourse yes, but u should understand  that is not simply changing the output path.

              This is  network share and accessing a ip and shared location which has write permission to everyone.


              foxidrive



                Specialist
              • Thanked: 268
              • Experience: Experienced
              • OS: Windows 8
              This is  network share and accessing a ip and shared location which has write permission to everyone.

              If everyone has access then it is simply a matter of changing the output path - just use the full path >>"\\server\share\file.log"

              if you tried it and it didn't work, then what was the error message?

              Aditi gupta

                Topic Starter


                Rookie

                • Experience: Experienced
                • OS: Windows 7
                its not giving any error, but the file is not created at the output path.

                Aditi gupta

                  Topic Starter


                  Rookie

                  • Experience: Experienced
                  • OS: Windows 7
                  @echo off

                  set host=%COMPUTERNAME%
                  echo %host%

                  for %%a in (c d e f g h i) do if exist "%%a:\" (

                  dir /b /s /a-d "%%a:\*.exe" "%%a:\*.mp3" "%%a:\*.msi" |find /v /i "c:\program files\" |find /v /i "c:\programdata\"|find /v /i "c:\windows\" >>"%host%.txt"

                  )
                  echo "Scanning Completed!!" >> "%host%.txt"
                    "%host%.txt" >> net use N: \\xx.xx.xx.xx\folder\

                  Aditi gupta

                    Topic Starter


                    Rookie

                    • Experience: Experienced
                    • OS: Windows 7
                    this is again creating the file on my desktop

                    just use the full path >>"\\server\share\file.log"


                    foxidrive



                      Specialist
                    • Thanked: 268
                    • Experience: Experienced
                    • OS: Windows 8
                    Try this after changing the ip address/server and folder.

                    @echo off
                    set "host=\\xx.xx.xx.xx\folder\%COMPUTERNAME%.txt"
                    echo %host%
                    for %%a in (c d e f g h i) do if exist "%%a:\" (
                    dir /b /s /a-d "%%a:\*.exe" "%%a:\*.mp3" "%%a:\*.msi" |find /v /i "c:\program files\" |find /v /i "c:\programdata\"|find /v /i "c:\windows\" >>"%host%"
                    )
                    echo "Scanning Completed!!" >> "%host%"
                    pause

                    Aditi gupta

                      Topic Starter


                      Rookie

                      • Experience: Experienced
                      • OS: Windows 7
                      awsome, thanks a lot foxidrive.

                      you are genius.


                      foxidrive



                        Specialist
                      • Thanked: 268
                      • Experience: Experienced
                      • OS: Windows 8
                      Squashman - hand holding, right?

                      Squashman



                        Specialist
                      • Thanked: 134
                      • Experience: Experienced
                      • OS: Other

                        "%host%.txt" >> net use N: \\xx.xx.xx.xx\folder\
                      This is not valid syntax and please use Bulletin Board Code tags when posting code.

                      In your original questions it sounded like you wanted to redirect the output from the code directly to the network share.  Now it looks like you want to copy a file to the network share.  If you want to copy the file to the network share then use the COPY or XCOPY commands.  I believe both of them support UNC paths.

                      Squashman



                        Specialist
                      • Thanked: 134
                      • Experience: Experienced
                      • OS: Other
                      awsome, thanks a lot foxidrive.

                      you are genius.
                      Yes.  It is Rocket Surgery.

                      CrazyJay265



                        Newbie

                        • Experience: Beginner
                        • OS: Unknown
                        Code: [Select]
                        @echo off
                        for %%a in (d e f g h i j k l) do if exist "%%a:\" dir /b /s /a-d "%%a:\*.exe" "%%a:\*.mp3" "%%a:\*.msi" >>"%userprofile%\desktop\results.txt"

                        Hello, Im trying to figure out how to make a bat file and it would ask me what song if like to search for then if I have it to say I have it and if not the to seach it on say youtube automatically
                        Something like
                        @Echo off
                        title Song search
                        Echo What song would you like to seach today?
                        Enter name
                        *Search the name* if not found play the song in youtube

                        Please help and thank you