Computer Hope
Microsoft => Microsoft DOS => Topic started by: Blisk on May 18, 2017, 12:44:52 PM
-
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.
like
d:\users\mike\log\logfileL22102017.txt
d:\users\john\log\logfileH12022017.txt
d:\users\claire\log\logfileH03042017.txt
d:\users\billy\log\logfileL10112017.txt
all that files logfile*.txt in new file copied_logfiles.txt
copied_logfiles.txt will be in folder d:\users\copied_logfiles.txt also batch which will create that file.
copied_logfiles.txt will look like this when I open.
d:\users\mike\log\--->L.txt
d:\users\john\log\--->H.txt
d:\users\claire\log\--->H.txt
d:\users\billy\log\--->L.txt
I need a list of files in one txt file if users logfile is marked with H or L so I need to check users folder and which txt file is currently in L or H.
Now I need to check every user subfolder and check if there is logfileL22102017.txt with L in it or logfileH03042017.txt with H in it.
If it is more than 5 hours L than I need to do something to get for user to have logfileH03042017.txt with H in it.
Can someone help me with batch?
-
You can use wildcards (https://www.computerhope.com/jargon/w/wildcard.htm) in a directory command.
For example, lets say you are in the d:\users directory and wanted to find all files beginning with logfileh that were text files. You could type the following command.
dir logfileh*.txt /s
The "/s" will display results for all subdirectories from the d:\users directory.
If you wanted the results to go to a text file you could use the append symbol (https://www.computerhope.com/jargon/a/appendsy.htm) to append the results to a text file. Below is an example of the same command.
dir logfileh*.txt /s > c:\users\copied_logfiles.txt
Like any command line command this command can be added to any batch file.
-
Hi ;)
There is another command named WHERE (https://ss64.com/nt/where.html) : To locate and display files in a directory tree
WHERE (Windows 2003 + )
Locate and display files in a directory tree.
The WHERE command is roughly equivalent to the UNIX 'which' command. By default, the search is done in the current directory and in the PATH.
Syntax
WHERE [/r Dir] [/q] [/f] [/t] Pattern ...
WHERE [/q] [/f] [/t] [$ENV:Pattern
key
/r A recursive search, starting with the specified Dir directory.
/q Don’t display the files but return either an exit code of 0 for success
or 1 for failure.
/f Display the output file name in quotation marks.
/t Display the size, time stamp, and date stamp of the file.
pattern The Drive\Directory\file, or set of files to be found.
you can use wildcard characters ( ? * ) and UNC paths.
ENV Path to search where ENV is an existing environment variable containing one or more paths.
By default, WHERE searches the current directory and the paths specified in the PATH environment variable. Optional search paths (in pattern) should not be used in conjunction with /r Dir.
-
I know but I don't know how to put it in batch for my case
-
I 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
for /f "tokens=*" %a in ('dir .\log /B /S) do echo %~fa %~za >> d:\users\drivers\mike\testfolder\List.txt
this one says can not find file
for /f "tokens=*" %a in ('dir .\new /s /b /A-D "*.txt"') do echo %~fa %~za >> d:\users\drivers\mike\testfolder\List.txt
-
Hi ;)
You can give a try for this batch file : Search_LogFiles.bat
@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
-
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
In this case you can try like that if i understood what you mean ?
@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.txt
-
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.
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
-
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.
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
Did you mean something like that ?
@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.