如何使用批处理脚本将内容添加到具有各种路径的文本文件中?

时间:2021-11-24 05:37:56

I am new to batch scripting and I was trying out new stuff.

我是批处理脚本的新手,我正在尝试新的东西。

I have a file sample.txt. It has various paths which looks like this:

我有一个文件sample.txt。它有各种路径,如下所示:

C:\Users\admin\Desktop\Sample\New Text Document1.txt
C:\Users\admin\Desktop\Sample\New Text Document2.txt
C:\Users\admin\Desktop\Sample\New Text Document3.txt
C:\Users\admin\Desktop\Sample\New Text Document4.txt

I want to add text in this path before the file name.

我想在文件名之前在此路径中添加文本。

I want the file to look like this:

我希望文件看起来像这样:

C:\Users\admin\Desktop\Sample\Backup Folder\New Text Document1.txt
C:\Users\admin\Desktop\Sample\Backup Folder\New Text Document2.txt
C:\Users\admin\Desktop\Sample\Backup Folder\New Text Document3.txt
C:\Users\admin\Desktop\Sample\Backup Folder\New Text Document4.txt

1 个解决方案

#1


1  

try this:

@echo off


set "file=sample.txt"
set "add_=Backup Folder\"

break>temp
for /f "usebackq tokens=* delims=" %%# in ("%file%") do (
    echo %%~dp#%add_%%%~nx#
)>>temp

move /y temp "%file%"

#1


1  

try this:

@echo off


set "file=sample.txt"
set "add_=Backup Folder\"

break>temp
for /f "usebackq tokens=* delims=" %%# in ("%file%") do (
    echo %%~dp#%add_%%%~nx#
)>>temp

move /y temp "%file%"