Answer the question
In order to leave comments, you need to log in
How to parse txt file using bat file?
Good day! There is a folder with text files.
File structure:
Name - Ivan
Surname - Ivanov
Phone - 79999999999
You need to create a folder for each such user and move the corresponding file there. The name of the folders is the user's phone number. I tried to write the following bat script to solve the problem:
@echo off
set Src = D:\tmp
For %%i in ("%Src%\*.txt") do (
set filepath = %%i
For %%a in ('findstr "Телефон" %filepath%') do (
set foldername = %%a
md %Src%\%foldername%
)
move %Src%\%%~nxi %Src%\%foldername%
)
Answer the question
In order to leave comments, you need to log in
Look at the description:
for /?
Your case is for /f - reads the file line by line and tokenizes it.
For example:
for /f "usebackq tokens=1,2 delims= -" %%a in ("%Src%\*.txt") do (
echo.%%a = %%b
)
in cmd so that the assigned value is used further
in the lines
set foldername=%%a
md %Src%\%foldername%
set foldername=%%a
md %Src%\!foldername!
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question