1

I have a batch file which saves all file names in current directory to txt file,

  1. i want to save as well directory name.
  2. and then put quotes around them
    so output file would look like this:

"Directory\File_Name"

This what i done so far

dir /b %path % > path.txt
Andrew
  • 1,507
  • 1
  • 22
  • 42
  • Storing quoted file paths in a text file just screams [X-Y Problem](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). What are you trying to accomplish? – SomethingDark Jul 17 '16 at 07:54
  • 2
    the code you posted does not make sense. – PA. Jul 17 '16 at 08:05
  • Try the solution provided in [Batch Files: List all files in a directory with relative paths](http://stackoverflow.com/questions/8385454) – Ashwani Kumar Jul 17 '16 at 09:55

1 Answers1

2

Give a shout for this batch file :

@echo off
Set "Folder=%~dp0"
Set "Log=%~n0.txt"
If Exist "%Log%" Del "%Log%"
for /f %%f in ('Dir /b /s "%Folder%"') do echo "%%f" >> "%Log%"
Start "" "%Log%"

Or something like that as @Ashwani Kumar posted in the comments :

Batch Files: List all files in a directory with relative paths

@echo off
Set "Folder=%~dp0"
Set "Log=%~n0.txt"
If Exist "%Log%" Del "%Log%"
SETLOCAL DisableDelayedExpansion
SET "r=%__CD__%"
FOR /R . %%F IN (*) DO (
  SET "p=%%F"
  SETLOCAL EnableDelayedExpansion
  ECHO("!p:%r%=!" >> "%Log%"
  ENDLOCAL
)
Start "" "%Log%"
Community
  • 1
  • 1
Hackoo
  • 18,337
  • 3
  • 40
  • 70