按照文件名筛选并复制指定文件bat
时间: 2023-07-29 12:04:40 浏览: 299
对于这个任务,你可以编写一个批处理脚本来筛选并复制指定的文件。
首先,你需要打开一个记事本文件,并在其中编写以下脚本:
```
@echo off
set source_path=C:\source_folder
set destination_path=C:\destination_folder
set file_extension=.txt
for %%F in ("%source_path%\*%file_extension%") do (
copy "%%F" "%destination_path%\%%~nxF"
)
echo 指定文件已复制完成。
pause
```
请注意,上面的脚本中的 `source_folder` 是指你想要筛选文件的源文件夹路径,`destination_folder` 是指你想要将文件复制到的目标文件夹路径,`file_extension` 是指你想要筛选文件的扩展名。
对于脚本中的 `copy` 命令,它会将符合筛选条件的文件复制到目标文件夹中。`%%~nxF` 是用来获取被复制文件的文件名和扩展名。
保存文件,并将其后缀改为 `.bat`,例如 `filter_and_copy.bat`。然后,你可以双击运行这个批处理脚本。
当脚本运行时,它会在源文件夹中筛选出符合扩展名的文件,并将它们复制到目标文件夹中。在复制完成后,脚本会显示“指定文件已复制完成。”并暂停脚本的执行。
请确保在运行脚本之前,你已经将源文件夹路径、目标文件夹路径和文件扩展名适当地修改为你自己的值。
阅读全文
相关推荐
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![txt](https://img-home.csdnimg.cn/images/20241231045021.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231044901.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)