Note that in the above batch file, there is a TAB in between %%~nF and %%F.
Also, you will need to change the drive and folder to match your files. ( such as O:\Clients ;)
Main Topics
Browse All TopicsI need to create a list of files and pathnames for a directory and output the list to a TXT file so I can import into my database.
The files are scattered at various folder levels in a huge (500,000 files) folder structure. The output in my text file should be TAB delimited and look like this:
<FILENAME> <PATHNAME + FILENAME>
Any help greatly appreciated.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Oops,
I should also mention that if you want to list only files and not directories, the DIR command should be modified to the following:
DIR /S /B /A-D
The other thing is that any files or directories with spaces in the name will not get output correctly unless you use a DELIMS to ignore the spaces.
So the full command should be something like this if run directly from the command line:
FOR /F "DELIMS=" %F IN ('DIR /S /B /A-D O:\Clients\*.*') DO @ECHO %~nF %~nxF %F %~dpF>>Output.txt
Of course, the double spaces after the ECHO should be tabs.
pb
Hi AmazingTech,
Perhaps you should test the command line solution provided before stating that it doesn't work. It works just fine on my system. It works from a batch file when the variable delimiters are doubled and works from the command-line as is, so long as you haven't changed the auto completion character to the tab key.
I prefer the simple, working 1 liner.
Personally, I also prefer pipe delimited files for import into my SQL databases. The pipe symbol is rarely used elsewhere and makes a great delimiter.. If you go this route, it will need to be escaped from the command line, like this:
FOR /F "DELIMS=" %F IN ('DIR /S /B /A-D O:\Clients\*.*') DO @ECHO %~nF^|%~nxF^|%F^|%~dpF>>Outp
pb
Business Accounts
Answer for Membership
by: knightEknightPosted on 2008-08-16 at 01:39:41ID: 22243530
@echo off
c:
cd c:\folder
for /f %%F in ('dir/s/b *.*') do @echo %%~nF %%F > c:\output.txt