Need to find some specific files in removable drive
Moderator: DosItHelp
-
- Posts: 8
- Joined: 09 Apr 2012 17:13
Need to find some specific files in removable drive
Friends I need to find/search for the existence of some files and store the result with filename and existence/non-existence in a txt file.
for example
I need to find new.txt, three.jpg, ty.doc in drive D: and store the result in txt file as filename found/not found.
Thanks in advance.
for example
I need to find new.txt, three.jpg, ty.doc in drive D: and store the result in txt file as filename found/not found.
Thanks in advance.
Re: Need to find some specific files in removable drive
DIR /S should help to find the files. Try:
Regards
aGerman
Code: Select all
@echo off &setlocal
set "drive=D:\"
set "file1=new.txt"
set "file2=three.jpg"
set "file3=ty.doc"
>"found.txt" (
for /f "delims=" %%i in ('dir /a-d /b /s "%drive%%file1%" "%drive%%file2%" "%drive%%file3%" 2^>nul') do (
if "%%~nxi"=="%file1%" (
echo "%%i"
set "found1=true"
)
if "%%~nxi"=="%file2%" (
echo "%%i"
set "found2=true"
)
if "%%~nxi"=="%file3%" (
echo "%%i"
set "found3=true"
)
)
)
>"not found.txt" (
if not defined found1 echo "%file1%"
if not defined found2 echo "%file2%"
if not defined found3 echo "%file3%"
)
Regards
aGerman
Re: Need to find some specific files in removable drive
I'd just change this:
if "%%~nxi"==
to this in three places, to make the match case insensitive.
if /i "%%~nxi"==
if "%%~nxi"==
to this in three places, to make the match case insensitive.
if /i "%%~nxi"==
-
- Posts: 8
- Joined: 09 Apr 2012 17:13
Re: Need to find some specific files in removable drive
Thanks a billion,
But I need to find hundreds of files when I tried it took more than 5 minutes, can we still have any optimized code with getting filename from an ext. text file.
But I need to find hundreds of files when I tried it took more than 5 minutes, can we still have any optimized code with getting filename from an ext. text file.
Re: Need to find some specific files in removable drive
Is two batch files an option?
edited
edited
Last edited by foxidrive on 10 Apr 2012 07:21, edited 1 time in total.
-
- Posts: 8
- Joined: 09 Apr 2012 17:13
Re: Need to find some specific files in removable drive
Thanks, I need files that are not found in the list.txt also
Re: Need to find some specific files in removable drive
Where are they found? Do you want to pass filenames on the command line to the batch file?
-
- Posts: 8
- Joined: 09 Apr 2012 17:13
Re: Need to find some specific files in removable drive
Thanks a lot for your timely help. Like the previous post code I need output files such as not-found.txt and found.txt in your code only found.txt is the only output.
For example I need to find 3 three files named one.txt, two.png, three.jpg in drive D: and drive d: has only one file say one.txt, your code returns only the files which are found in D: but I need both in separate files as found.txt(contains one.txt) and not found.txt (contains two.png, three.jpg) hope its clear now.
For example I need to find 3 three files named one.txt, two.png, three.jpg in drive D: and drive d: has only one file say one.txt, your code returns only the files which are found in D: but I need both in separate files as found.txt(contains one.txt) and not found.txt (contains two.png, three.jpg) hope its clear now.
Re: Need to find some specific files in removable drive
Does this work for you? The other first batch file is still needed to produce the filelist.txt
Edit: reversed the last line
Code: Select all
:: create file list
@echo off
dir d:\ /a-d /b /s >filelist.txt
Code: Select all
@echo off
:: search for filenames
(
echo \new.txt
echo \three.jpg
echo \ty.doc
) > "list.txt
findstr /i /g:"list.txt" "filelist.txt" >"foundfiles.txt"
findstr /v /i /g:"filelist.txt" "list.txt" >"notfoundfiles.txt"
Edit: reversed the last line
Last edited by foxidrive on 10 Apr 2012 08:19, edited 1 time in total.
-
- Posts: 8
- Joined: 09 Apr 2012 17:13
Re: Need to find some specific files in removable drive
notfound.txt lists all files from the drive D: except the one found, To made it simple
Code: Select all
Drive D: contains the following files
------------------------------------
ty.doc
two.jpg
INPUT
-------
List.txt (files that i need to search/find in D:)
---------------------------------------------
ty.doc
two.jpg
three.png
OUTPUT:
-----------
Found.txt contents
----------------------
ty.doc
two.jpg
Notfound.txt Contents
---------------------
three.jpg
Re: Need to find some specific files in removable drive
Try the batch above again - I edited the post.
-
- Posts: 8
- Joined: 09 Apr 2012 17:13
Re: Need to find some specific files in removable drive
Tried notfound.txt displays all the contents of list.txt file
Re: Need to find some specific files in removable drive
Ok, sorry for the false leads. This has been lightly tested. Try the batch file at the bottom which simulates a disk with three files, one of which is not in the list to be found.
Code: Select all
@echo off
:: create file list
@echo off
dir d:\ /a-d /b /s >filelist.txt
del "filelist2.txt" 2>nul
for /f "delims=" %%a in (
'type "filelist.txt"'
) do echo>>"filelist2.txt" \%%~nxa
Code: Select all
@echo off
:: search for filenames
(
echo \new.txt
echo \three.jpg
echo \ty.doc
) > "list.txt
findstr /i /g:"list.txt" "filelist.txt" >"foundfiles.txt"
findstr /v /i /g:"filelist2.txt" "list.txt" >"notfoundfiles.txt"
Code: Select all
@echo off
:: create file list
(
echo d:\folder\new.txt
echo d:\folder 3\threeB.jpg
echo d:\a place here\ty.doc
) > "filelist.txt
del "filelist2.txt" 2>nul
for /f "delims=" %%a in (
'type "filelist.txt"'
) do echo>>"filelist2.txt" \%%~nxa
@echo off
:: search for filenames
(
echo \new.txt
echo \three.jpg
echo \ty.doc
) > "list.txt
findstr /i /g:"list.txt" "filelist.txt" >"foundfiles.txt"
findstr /v /i /g:"filelist2.txt" "list.txt" >"notfoundfiles.txt"
-
- Posts: 8
- Joined: 09 Apr 2012 17:13
Re: Need to find some specific files in removable drive
Still I get all files in notfoundfiles.txt
Re: Need to find some specific files in removable drive
Try the last batch file above which demonstrates the technique:
I only get this filename in the notfound file.
\three.jpg
I only get this filename in the notfound file.
\three.jpg