DOS Batch命令一次处理1个文件 [英] DOS Batch command to process 1 file at a time
问题描述
我正在尝试执行某项任务,要求我从一个文件夹中读取文件(一次读取一个),该文件夹可能具有未定义数量的文件。我需要能够将文件夹中的第一个文件移动到新位置,然后使用另一个批处理文件执行另一个任务。主要目的是一次读取一个文件,而不是执行*。*来读取所有文件立刻。
任何帮助将不胜感激!
谢谢
I am trying to execute a certain task where i am required to read files (one at a time) from a folder which can have undefined number of files. I need to be able to MOVE the first file in the folder to a new location and then execute another task with another batch file.The main aim is to read one files at a time instead of doing a *.* which will read all files at once. Any help would be appreciated ! Thanks
推荐答案
您可以使用for命令,如下所示:
You can use a for command something like this:
for /R c:\test\src %i IN (*.*) DO (
MOVE %i C:\test\dest
YourBatch.bat C:\test\dest\%~nxi
)
如果将此命令放入批处理文件中,则需要将%符号加倍,如下所示:
If you are putting this command in a batch file you will need to double up the % symbols like this:
for /R c:\test\src %%i IN (*.*) DO (
MOVE %%i C:\test\dest
YourBatch.bat C:\test\dest\%%~nxi
)
在YourBatch.bat文件中使用%1%这样的文件名:
In the YourBatch.bat file access the file name using %1% something like this:
@echo off
type %1%
编辑:
要仅处理一个文件,只需在以下位置退出第一个循环的结尾:
To only process one file simply exit at the end of the first loop:
for /R c:\test\src %%i IN (*.*) DO (
MOVE %%i C:\test\dest
YourBatch.bat C:\test\dest\%%~nxi
exit
)
这篇关于DOS Batch命令一次处理1个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!