0

I'm making a batch script where the User do the scanning of a folder and batch list the files of the same to a TXT and after it is done scanning the TXT list looking for files with the same name as a list, predetermined, however I have problems after

1 - I have not the slightest idea of how do I show file that was found in the separate list

Example:

My list:

VideoTeste
Family
Myfavoritesong
My Song

Result in Documentos.txt:

Videoteste.avi
Family.exe
family.jpg
MY_1231dFamilyxzsaxad.jpg
MyFavoritesong.mp3
Folder_Family
My Song.mp3



Result in Downloads.txt:

Videoteste.rar
Family_235.dat
MyFavoritesong_&.mp3
My Song.mp3


Result in Temp.txt:

Videoteste.rar
Family_235.dat
MyFavoritesong_&.mp3
My Song.mp3

2 - This list is not fixed as well as local and this would in a way where the local and items could not cause errors to the script as spaces or &.

Note:

1 - The lists are in the temp folder in several .txt files

2 - If possible if it were not found anything in a .txt file information appeared that nothing was found in the output file.

Humberto Freitas
  • 461
  • 1
  • 6
  • 21
  • Start with `for /f "usebackq tokens=*" %%G in ("files\my list.txt") do @echo "%%~G"` and then you could replace that simple `echo` with `dir /B "any path\*%%~G*.*"`. Feel free to [edit your question](http://stackoverflow.com/posts/27659557/edit), add your achievements and ask more if you struck on something... – JosefZ Dec 26 '14 at 17:51
  • What you posted has Helped me a lot, I wanted was something like this ... with your code I'll be able to finish my script. Thank you very much. – Humberto Freitas Dec 28 '14 at 01:34

1 Answers1

1

Here is a batch file to

  • scan in each folder listed at top of the batch file
  • for files and folders in a list file with fixed name
  • and write just the names of all found files and folders into a text file with same name as the scanned folder.

An information message is output if no file/folder from list was found in a specified folder.

So the batch file does not search in text files for names of files and folders in list file.
But I suppose the text files in temp folder were just created before also with batch code.

@echo off
call :SearchFromList "C:\Temp\Documentos"
call :SearchFromList "C:\Temp\Downloads"
call :SearchFromList "C:\Temp\Temp"
goto :EOF

:SearchFromList
set "Folder=%~1"
set "ListFile=C:\Temp\%~nx1.txt"

echo Scan folder "%Folder%" for files in "My List.txt"
echo and write found files and folders to "%ListFile%".
echo.

if exist "%ListFile%" del /F "%ListFile%"
for /F "usebackq delims=" %%N in ("C:\Temp\My List.txt") do (
    for /F "delims=" %%F in ('dir /B "%Folder%\*%%N*" 2^>nul') do echo>>"%ListFile%" %%~nxF
)

if not exist "%ListFile%" (
    echo>"%ListFile%" No file found from list.
    echo No file found from list in folder "%Folder%".
    echo.
)
goto :EOF

See Batch creation of a list of folders : can't echo accented characters on what to do to get file and folder names with local characters written with local GUI code page into a text file.

Community
  • 1
  • 1
Mofi
  • 46,139
  • 17
  • 80
  • 143