Looping

  • Thread starter Thread starter Franck Diastein
  • Start date Start date
F

Franck Diastein

Hi,

I want to list files in a directory, how to do it ?

If I do this:

for %%f in (c:\svn_bak\dumps\*.*) do echo %%f

I have files with full path... I only need file names...

TIA
 
Franck said:
Hi,

I want to list files in a directory, how to do it ?

If I do this:

for %%f in (c:\svn_bak\dumps\*.*) do echo %%f

I have files with full path... I only need file names...

TIA

Try
for %%f in (c:\svn_bak\dumps\*.*) do echo %%~nxf

See for /? for details of the tilde commands "fdpnxsatz"

HTH
 
In addition to Togir's suggestion some further info. What you put in the brackets is whether there is a path or not.

EG
for %%f in (c:\svn_bak\dumps\*.*) do echo %%f

includes paths, while

CD c:\svn_bak\dumps\
for %%f in (*.*) do echo %%f

doesn't include paths
 
David said:
In addition to Togir's suggestion some further info. What you put in the brackets is whether there is a path or not.

EG
for %%f in (c:\svn_bak\dumps\*.*) do echo %%f

includes paths, while

CD c:\svn_bak\dumps\
for %%f in (*.*) do echo %%f

doesn't include paths
In case the current drive isn't the same I'd prefer:

CD /D c:\svn_bak\dumps\
for %%f in (*.*) do echo %%f

or, even better

pushd c:\svn_bak\dumps\
for %%f in (*.*) do echo %%f
popd

BTW I've still to work some time getting Torgeirs current expertise.
 
Franck said:
Hi,

I want to list files in a directory, how to do it ?

If I do this:

for %%f in (c:\svn_bak\dumps\*.*) do echo %%f

I have files with full path... I only need file names...

TIA

Umm . . .
dir /a-d /b c:\svn_bak\dumps

Or, if you actually do need only files with "." in them:
dir /a-d /b c:\svn_bak\dumps\*.*

If you want to list directories too, choose one of these:
dir /b c:\svn_bak\dumps
dis /b c:\svn_bak\dumps\*.*

Unless I'm missing some point you were trying to make? Why are you
using FOR?

David
Stardate 4976.6
 
This will get you raw file names:
for /f %i in ('dir /b c:\svn_bak\dumps /a-d') do @echo %i

This will get you raw directory and file names:
for /f %i in ('dir /b c:\svn_bak\dumps /a') do @echo %i

I suppose you will use the output for something more than just echo.
If not, the dir command alone will do the trick.
 
Back
Top