Batch scripts written in Windows Command Prompt. del /s 1.docxs Batch script written in Command Prompt. del /s 1.docx
The function of this batch script is to delete the file named "1.docx", using the "/s" flag to delete the files in all subdirectories.
If I have multiple files to delete, for example, I have "1.mlx", "2.mlx", "3.mlx", "4.mlx", "1.docx" which I want to delete, how about the script Revise
@echo off
del /s 1.mlx
del /s 2.mlx
del /s 3.mlx
del /s 4.mlx
del /s 1.docx
In this example, @echo off
the command is used to disable echoing of the command prompt when executing the script, making the output more concise and clear. Then, del /s
delete each file individually using the command.
@echo off
set fn=sanciyangtiao.mlx
for /f "tokens=*" %%i in ('dir/s/b/ad') do copy %fn% "%%i"
pause
The first line @echo off
is used to turn off the echoing of the output execution command in the prompt.
The second set fn=sanciyangtiao.mlx
line fn
sets the variable to the value "sanciyangtiao.mlx".
The third line for /f "tokens=*" %%i in ('dir/s/b/ad') do copy %fn% "%%i"
uses a for loop to iterate through each dir /s /b
subdirectory (/ad) listed by . It then fn
copies the files specified in to each of these directories.
Finally, pause
execution of the script is stopped until any key is pressed.
It appears to be designed to copy a specific file ( sanciyangtiao.mlx
) to every subdirectory in the current directory and any subdirectories within it.
If I want to copy multiple files to each subdirectory in the current directory and any subdirectories in it, for example, I have "1.mlx", "2.mlx", "3.mlx", "4.mlx", " 1.docx" these multiple files want to be copied, how to modify this script
@echo off
set fns="1.mlx" "2.mlx" "3.mlx" "4.mlx" "1.docx"
for /f "tokens=*" %%i in ('dir/s/b/ad') do (
for %%j in (%fns%) do (
copy %%j "%%i"
)
)
pause
This script will store the list of files "1.mlx"
, "2.mlx"
, "3.mlx"
, "4.mlx"
, and in the variable . It then uses two nested loops to go through each subdirectory and copy each file to each subdirectory."1.docx"
fns
The first loop iterates through each subdirectory, while the second loop iterates through the list of files. In the second loop, the variable %%j
is set to each filename and copied using the subdirectory found in the first loop.