DOS Batch command to process 1 file at a time

dos

Solution

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
)

In the YourBatch.bat file access the file name using %1% something like this:

@echo off
type %1%

EDIT:

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
)

Problem

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

Original source