| 1. |
Solve : search for mutiple txt files and copy file name and path into one txt file? |
|
Answer» How can I search for multiple txt files with the partly same name under multiple subfolders and COPY that filename and path to that file into one txt file. WHERE (Windows 2003 + )I know but I don't know how to put it in batch for my caseI have managed to make a list with paths but cant make it to write at the end of path if file is logH.txt or logL.txt Code: [Select]for /f "tokens=*" %a in ('dir .\log /B /S) do echo %~fa %~za >> d:\users\drivers\mike\testfolder\List.txtthis one says can not find file Code: [Select]for /f "tokens=*" %a in ('dir .\new /s /b /A-D "*.txt"') do echo %~fa %~za >> d:\users\drivers\mike\testfolder\List.txtHi You can give a try for this batch file : Search_LogFiles.bat Code: [Select]echo off Title Searching files . . . Color 9E & Mode con cols=75 lines=3 set "Master_Folder=C:\users" set "Pattern=logfile*.txt" set "LogSearch=%~dpn0.txt" echo( echo Please wait ... Searching "%Pattern%" files is in progress ... Where /R "%Master_Folder%" "%Pattern%" /F >"%LogSearch%" 2>&1 start "" "%LogSearch%"I have one problem here. loghi*.txt files are also in folder logfiles and in its subfolder new it is only one. And I need only file from subfolder new, this script finds also fles in folder logfiles. d:\users\john\logfiles\logfileH12022017.txt this file I am looking for to write in txt d:\users\john\logfiles\new\logfileH12022017.txt Quote from: Blisk on May 23, 2017, 12:07:37 AM I have one problem here. In this case you can try like that if i understood what you mean ? Code: [Select]echo off Title Searching files . . . Color 9E & Mode con cols=75 lines=3 set "Master_Folder=C:\users" set "Pattern=logfile*.txt" set "LogSearch=%~dpn0.txt" echo( echo Please wait ... Searching "%Pattern%" files is in progress ... Where /R "%Master_Folder%" "%Pattern%" /F >"%LogSearch%" 2>&1 Type "%LogSearch%" | find /I "new" > NewLog.txt start "" NewLog.txtI named that batch test.bat and it also creates test.txt where all logfile*.txt are in, from \logfiles folder too which is wrong. But at the same time it opens notepad named NewLog.txt where is result which I want, from folder \new How to do this to get results saved in NewLog.txt and there is no test.txt created and doesn't open notepad.exe but save directly to NewLog.txt file. And is it possible to get result in txt file from this logfileH12022017.txt to this logfileH? Hot Quote from: Blisk on May 23, 2017, 02:37:06 AM I named that batch test.bat and it also creates test.txt where all logfile*.txt are in, from \logfiles folder too which is wrong.Did you mean something like that ? Code: [Select]echo off Title Searching files . . . Color 9E & Mode con cols=75 lines=3 set "Master_Folder=C:\users" set "Pattern=logfile*.txt" Rem Name it as you want set "LogSearch=TextFile_As_You_want_here.txt" echo( echo Please wait ... Searching "%Pattern%" files is in progress ... Where /R "%Master_Folder%" "%Pattern%" /F >"%LogSearch%" 2>&1 REM We filter our search into file named NewLog.txt Type "%LogSearch%" | find /I "new" > NewLog.txt Rem We delete the "%LogSearch%" If exist "%LogSearch%" Del "%LogSearch%"Thank you this is what I want. |
|