ソースファイルがありますblue01.環境(テキストファイル)
コピーする必要があるテキストこのファイルに保存して、以下のすべてのファイルに貼り付けますが、元の名前で。
blue02.environment
yellow01.environment
yellow02.environment
yellow03.environment
purple01.environment
purple02.environment
...
使用できるバッチコマンドを教えていただけますか?
答え1
これを試して:
#!/bin/bash
# the file you want the content to be copied
master=/your_dir/master_file
# get the content
content="$(cat $master)"
# loop the files .environment
for file in /your_dir/*.environment; do
# if the file is not the master file copy the content
[ "$file" != "$master" ] && echo "$content" > "$file"
done
答え2
これはどうですかバッチファイル:
rem // Define constants here:
set "_ROOT=." & rem // (path to root directory; `.` is current, `%~dp0.` is batch file parent)
set "_MASK=*.environment" & rem // (pattern to match files to process)
set "_MASTER=blue01.environment" & rem // (name of master file)
rem // Change to root directory:
pushd "%_ROOT%" && (
// Iterate over all matching files:
for %%I in ("%_MASK%") do @(
rem // Exclude master file to be overwritten:
if /I not "%%~nxI" == "%_MASTER%" (
rem // Copy master file onto current file:
copy /Y "%_MASTER%" "%%~I" > nul
)
)
rem // Return from root directory:
popd
)