Computer Hope

Microsoft => Microsoft DOS => Topic started by: Aditi gupta on May 27, 2014, 04:21:58 AM

Title: batch file to find all the .exe ,mp3,msi files and list the path such file
Post by: Aditi gupta on May 27, 2014, 04:21:58 AM
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
Title: Re: batch file to find all the .exe ,mp3,msi files and list the path such file
Post by: foxidrive on May 27, 2014, 05:15:06 AM
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"
Title: Re: batch file to find all the .exe ,mp3,msi files and list the path such file
Post by: Aditi gupta on May 27, 2014, 05:33:39 AM
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.?
Title: Re: batch file to find all the .exe ,mp3,msi files and list the path such file
Post by: foxidrive on May 27, 2014, 06:08:50 AM
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.
Title: Re: batch file to find all the .exe ,mp3,msi files and list the path such file
Post by: Aditi gupta on May 27, 2014, 09:28:17 PM
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.

Title: Re: batch file to find all the .exe ,mp3,msi files and list the path such file
Post by: Squashman on May 27, 2014, 10:07:27 PM
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.
Title: Re: batch file to find all the .exe ,mp3,msi files and list the path such file
Post by: Aditi gupta on May 27, 2014, 10:29:50 PM
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
Title: Re: batch file to find all the .exe ,mp3,msi files and list the path such file
Post by: Squashman on May 27, 2014, 10:37:14 PM
we must be from different planets as I can not figure out how this new question has anything to do with the original.
Title: Re: batch file to find all the .exe ,mp3,msi files and list the path such file
Post by: foxidrive on May 27, 2014, 11:20:46 PM
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

Title: Re: batch file to find all the .exe ,mp3,msi files and list the path such file
Post by: Aditi gupta on May 30, 2014, 02:52:55 AM
now want to store the output in shared location?

hostname should be the name of the file

 \\<ip address>\foldername\hostname.txt
Title: Re: batch file to find all the .exe ,mp3,msi files and list the path such file
Post by: Squashman on May 30, 2014, 06:22:00 AM
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.
Title: Re: batch file to find all the .exe ,mp3,msi files and list the path such file
Post by: Aditi gupta on June 02, 2014, 01:32:51 AM
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.

Title: Re: batch file to find all the .exe ,mp3,msi files and list the path such file
Post by: foxidrive on June 02, 2014, 03:30:08 AM
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?
Title: Re: batch file to find all the .exe ,mp3,msi files and list the path such file
Post by: Aditi gupta on June 02, 2014, 03:44:53 AM
its not giving any error, but the file is not created at the output path.
Title: Re: batch file to find all the .exe ,mp3,msi files and list the path such file
Post by: Aditi gupta on June 02, 2014, 04:25:24 AM
@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\
Title: Re: batch file to find all the .exe ,mp3,msi files and list the path such file
Post by: Aditi gupta on June 02, 2014, 05:15:29 AM
this is again creating the file on my desktop

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

Title: Re: batch file to find all the .exe ,mp3,msi files and list the path such file
Post by: foxidrive on June 02, 2014, 05:32:39 AM
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
Title: Re: batch file to find all the .exe ,mp3,msi files and list the path such file
Post by: Aditi gupta on June 02, 2014, 05:42:03 AM
awsome, thanks a lot foxidrive.

you are genius.

Title: Re: batch file to find all the .exe ,mp3,msi files and list the path such file
Post by: foxidrive on June 02, 2014, 06:14:41 AM
Squashman - hand holding, right?
Title: Re: batch file to find all the .exe ,mp3,msi files and list the path such file
Post by: Squashman on June 02, 2014, 06:34:37 AM

  "%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.
Title: Re: batch file to find all the .exe ,mp3,msi files and list the path such file
Post by: Squashman on June 02, 2014, 06:38:11 AM
awsome, thanks a lot foxidrive.

you are genius.
Yes.  It is Rocket Surgery.
Title: Re: batch file to find all the .exe ,mp3,msi files and list the path such file
Post by: CrazyJay265 on March 15, 2018, 06:05:02 PM
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