1. Use small script, so everything will be listed, but junctions won't be followed.
Works fine on Windows 7, unlike option below in this answer
let's call it dnj.cmd
(like in Dir No Junctions)
@(ECHO OFF
SETLOCAL ENABLEEXTENSIONS
CHCP 65001>NUL
IF "%~1"=="" (CALL :listDir .) ELSE CALL :listDir %*
EXIT /B
)
:listDir <path>
FOR /F "usebackq delims=" %%F IN (`DIR /B /A "%~1"`) DO ECHO %~1\%%~F
(
IF EXIST "%~1\*.*" FOR /F "usebackq delims=" %%F IN (`DIR /B /AD-L "%~1"`) DO CALL :listDir "%~1\%%~F"
IF "%~2"=="" EXIT /B
SHIFT
GOTO :listDir
)
First FOR/DIR for output, second FOR/DIR for recursion. This way, you can also adjust output parameters (specifically, DIR and ECHO arguments). For example, if you only want flat list of files in output without directories, use
FOR /F "usebackq delims=" %%F IN (`DIR %1 /B /A-D`) DO ECHO %%~F
in place of first FOR.
Invoking: dnj.cmd
path [path [...]]
Output redirection works same way as with conventional DIR, so
cmd /C "dnj.cmd "%USERPROFILE%" | CLIP"
works from Win+R ("Run") prompt.
2. If you're on Windows 10, use DIR /S /A-L
This way, junctions won't be listed, neither will be recurred with /S. On Windows 7, DIR /S /AD-L recurses junctions. Not sure about 8/8.1.
batch with output to text file:
CHCP 65001 & REM for UTF-8
DIR %* /B /S /A-L > out.txt
(pass path and additional DIR args as batch arguments)
cmd.exe to clipboard (can be invoked via Win+R):
cmd /C "CHCP 65001 & DIR "%USERPROFILE%" /B /S /A-L | CLIP"
Clipboard is unicode by default, but without CHCP beforehand, DIR output is in OEM codepage, so some characters may be lost.
Quotes after /C are required by CMD syntax, despite it looks weird with inner quotes around %USERPROFILE%
.
Did you try the
tree
command in Windows? You can pass the result of this command to a text file – Prasanna – 2016-10-10T12:08:16.627I would like to avoid using a scripting language (eg. python's
os.walk
), because I'd prefer a solution more easily portable (eg. a smaller single-file tool) – n611x007 – 2013-01-05T11:00:53.703Oh, and the tool should handle paths with spaces. :) – n611x007 – 2013-01-05T11:13:57.730
Note the text file doesn't have to be 'plain', it can be xml, csv, tsv, or anything text. – n611x007 – 2013-01-05T11:16:01.837
2I believe you could do this with robocopy, using the
/L
flag to prevent it from actually doing any copying. – Harry Johnston – 2013-01-07T02:24:10.993@HarryJohnston indeed, with
robocopy /XJ /L /E <dir> <dummy-target>
, the/XJ
flag skips the junctions and the/L
causes to list only!/E
is for recursion. Problem: too verbose. But it can be made slightly better with a win32 build of gnu's grep:robocopy /XJ /L /E <dir> <dummy-target> | grep -i "new dir\|new file"
. Still needs "applying" the containing directory for each file. – n611x007 – 2013-03-22T12:56:32.710