# Solved: Batch file to list file names in current Folder.



## muckmail (Jan 3, 2007)

I am trying to write a batch program the list the current directory files that end in *.dwg 
into a file on my C drive.
I have used the following code:
dir *.dwg /b >C:FileListing.txt
start notepad C:FileListing.txt

This code only gives file names in the current directory.
I need to have a list of path and file names in the file FileListing.txt
Is there a way to do that without including subdirectories??

Thank you,


----------



## carldickens (Sep 16, 2010)

try this and see if it gives you what you are asking. 

dir *.dwg /x /s >C:FileListing.txt

Carl


----------



## Squashman (Apr 4, 2003)

carldickens said:


> try this and see if it gives you what you are asking.
> 
> dir *.dwg /x /s >C:FileListing.txt
> 
> Carl


I wouldn't use short names.

This is what I would do.

```
dir *.dwg /a-d /b /s >C:\FileListing.txt
```


----------



## muckmail (Jan 3, 2007)

I will try the codes a above but the problem with adding /s is that it gives me all Path and files 
in all subdirectories. I only want paths and files in the current directory that I am at. 
Thank you,


----------



## muckmail (Jan 3, 2007)

The above codes did not work. I guess because of the /s mentioned in my previous post.
Any other suggestions.
Thank you,


----------



## Squashman (Apr 4, 2003)

Yeah I totally missed that. Give me a second. I will have a fix for you.


----------



## Squashman (Apr 4, 2003)

```
for /F "Tokens=* delims=" %I in ('dir /a-d /b *.txt') do echo %~fI>>C:\filelist.txt
```


----------



## Squashman (Apr 4, 2003)

Did that from the cmd line. Forgot you were doing this in batch. You need to double up on the Percent signs in a batch file.

```
for /F "Tokens=* delims=" %%I in ('dir /a-d /b *.dwg') do echo %%~fI>>C:\filelist.txt
```


----------

