How can batches replace all text content under a folder? _list

Source: Internet
Author: User
Find a batch to replace the contents of the text in the folder file ...
Give an example to say ha.
For example: D Disk 1 under the folder has 1.txt 2.txt 3.txt ... There are folders folder a folder B folder C Cut folder also txt and folder.
Folder a folder B folder c These three folders are under D:\1\, and there are subfolders below
All txt files are prohibited to replace 2 to allow 1


Ask how to replace the entire D:\1 folder in all txt text content ah ...


Does the following code apply to multiple content modifications?
Like banning 2 to allow 1.
And a ban on 5 to allow 5.
Ha ※ changed into AH


@echo off
Setlocal disabledelayedexpansion


Set "Dir=d:\1"
Set "Old= No 2"
Set "new= allow 1"


FINDSTR/S/m/c: "%old%" "%dir%\*.txt". Tmp


for/f "delims="%%i in (.. TMP) Do (
findstr/n. * "%%i" ... Tmp
(
for/f "delims="%%a in (.. TMP) Do (
Set Str=%%a
Setlocal enabledelayedexpansion
Set "str=!str:%old%=%new%!"
echo,!str:*:=!
Endlocal
)
) > "%%i"
)


Del.. Tmp
Copy Code


@echo off
Setlocal disabledelayedexpansion
Title Modification ...


REM setting
Set "Dir=d:\1"
Set replace_list= "Prohibit 2 = Allow 1" "Prohibit 5 = Allow 5" "Ha ※= Ah"


REM Output File list
dir/s/b/a:-d-r "%dir%\*.txt" ... TMP | | Goto exit


Number of REM statistics files
for/f%%i in (' "FIND/C/V" ") TMP "') Do (
set/a n_total =%%i, n_current = 0
)


REM Replacement
Set "s="
for/f "delims="%%i in (.. TMP) Do (
set/a N_current + + 1
findstr/n. * "%%i" ... Tmp
(
for/f "delims="%%a in (.. TMP) Do (
Set Str=%%a
Setlocal enabledelayedexpansion
set/p =%s: =%!n_current! /%n_total% <nul >con
Set str=!str:*:=!
For%%a in (%replace_list%) do (
If defined str set str=!str:%%~a!
)
echo,!str!
Endlocal
)
) > "%%i"
)


: Exit
Title Complete
Del.. TMP 2>nul
Echo
Echo Press any key to exit ...
Pause >nul


This post was last edited by Tmplinshi at 2011-6-19 14:24




Recommended with BWFR, the replacement speed is very fast.
Bwfr.exe "D:\1\*.txt"-s-f-argfile:list.txt
Copy Code
List.txt's File:
Prohibit 2-> allow 1
Prohibit 5-> allow 5
Hello, ※->.


----------------------------------------------------------------------
You can also use other delimiters, such as:
Bwfr.exe "D:\1\*.txt"-s-f-argfile:list.txt-dlm: "|"
Copy Code
List.txt's File:
Prohibit 2| allow 1
Prohibit 5| allow 5
Hello, ※|.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.