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

时间:2017-10-06 17:50:22

标签: windows batch-file

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

我有一个文件apply plugin: 'com.android.application' android { compileSdkVersion 26 buildToolsVersion "26.0.2" defaultConfig { applicationId "com.jystinz.roomdatabase" minSdkVersion 23 targetSdkVersion 26 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" multiDexEnabled true } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) compile 'com.android.support:appcompat-v7:26.1.0' compile 'com.android.support.constraint:constraint-layout:1.0.2' compile 'com.android.support:design:26.1.0' compile 'com.android.support:cardview-v7:26.1.0' compile 'com.android.support:recyclerview-v7:26.1.0' testCompile 'junit:junit:4.12' // reactive Network compile 'com.github.pwittchen:reactivenetwork-rx2:0.11.0' // room persistence compile 'android.arch.persistence.room:runtime:1.0.0-alpha9' compile 'android.arch.persistence.room:rxjava2:1.0.0-alpha9' annotationProcessor 'android.arch.persistence.room:compiler:1.0.0-alpha9' // images compile 'com.squareup.picasso:picasso:2.5.2' // barcode compile 'com.github.KingsMentor:MobileVisionBarcodeScanner:2.0.0' // retrofit2 compile 'com.squareup.retrofit2:retrofit:2.3.0' compile 'com.squareup.retrofit2:converter-gson:2.3.0' compile 'com.squareup.retrofit2:adapter-rxjava2:2.3.0' // gps compile 'com.google.android.gms:play-services-location:11.4.2' // dialog compile 'com.avast:android-styled-dialogs:2.3.3' compile 'com.afollestad.material-dialogs:core:0.9.4.7' } 。它有各种路径,如下所示:

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

1 个答案:

答案 0 :(得分:1)

试试这个:

@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%"