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

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.
 
B

billious

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top