how to retrieve a filename in a folder one at a time

  • Thread starter Thread starter Kok Yong Lee
  • Start date Start date
K

Kok Yong Lee

Hi there,

Is it possible to retrieve a filename from a folder one at a time?

e.g.
c:\> dir /b c:\tmp
junk1.txt
junk2.txt
junk3.txt


would like something like
c:\>mydir c:\tmp
junk1.txt


then do something with junk1.txt and delete the file and repeat the above
process again
c:\>mydir c:\tmp
junk2.txt


thanks in advanced.
 
Kok Yong Lee said:
Hi there,

Is it possible to retrieve a filename from a folder one at a time?

e.g.
c:\> dir /b c:\tmp
junk1.txt
junk2.txt
junk3.txt


would like something like
c:\>mydir c:\tmp
junk1.txt


then do something with junk1.txt and delete the file and repeat the above
process again
c:\>mydir c:\tmp
junk2.txt


thanks in advanced.

From the prompt:

for %i in (c:\tmp\*.txt) do echo yourcommand %i&echo del %i

* change "%" to "%%" throughout to execute as a line in a batch file.

* yourcommand is whatever command you wish to execute.

* the echos will show you what the command WOULD do. remove the ECHO to
actually ececute the command (be it yourcommand or del)
 
Back
Top