Batch scripts written in Windows Command Prompt

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 offthe command is used to disable echoing of the command prompt when executing the script, making the output more concise and clear. Then, del /sdelete 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 offis used to turn off the echoing of the output execution command in the prompt.

The second set fn=sanciyangtiao.mlxline fnsets 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 /bsubdirectory (/ad) listed by . It then fncopies the files specified in to each of these directories.

Finally, pauseexecution 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 %%jis set to each filename and copied using the subdirectory found in the first loop.

Guess you like

Origin blog.csdn.net/qq_53011270/article/details/131342115
Recommended