how to list all files and directories in given directory with full path but not recursive?

14

5

Somehow like dir /b command but I need also hidden and system files there. Built in dir command doesn't allow to list such 'hidden' files with the rest and I must use /s to have full path in there, which is of course non recursive.

I also played with windows version of ls command and there also no luck. To display full path you must add asterisk (mydir\*) at the end of directory you are listing, but this makes it recursive.

rsk82

Posted 2012-04-26T17:10:06.457

Reputation: 1 272

1I can solve part of your problem: the /a flag makes dir include hidden and system files. – Harry Johnston – 2012-04-30T01:32:45.783

Answers

9

If you don't want to install anything, you could also use the following command:

for /f "delims=" %a in ('cd') do @for /f %b in ('dir /b /a') do @echo %a\%b

You have to cd into the directory first or it won't work.

Dennis

Posted 2012-04-26T17:10:06.457

Reputation: 42 934

could you explain please, how this command works? – rubo77 – 2018-09-25T12:37:53.970

2or this! for /f "delims=" %b in ('dir /b /a') do @echo %cd%%b But yours is an interesting technique, quite generic – barlop – 2012-05-10T06:57:24.640

18

Try the following command:

dir /s /b /a

It will give ALL files, you can run it through FIND if you want or add a folder name.

bjkamp

Posted 2012-04-26T17:10:06.457

Reputation: 181

1

If you tried ls, why not just install cygwin? You can use find in cygwin:

find -name "*"

If you do install cygwin and want to use find in cygwin, make sure the find in cygwin is called by either using full path or insert cygwin bin path before system32 because Windows also has a find.exe.

Codism

Posted 2012-04-26T17:10:06.457

Reputation: 845

i checked unixutils, find is recursive :( – rsk82 – 2012-04-26T17:28:00.753

2@rsk82: With -maxdepth 1, it isn't. – Dennis – 2012-04-26T17:28:48.860

0

you could download sed with gnuwin32. This prepends the current directory.

Doing %cd% doesn't work.. so %cd:\=\\% converts every \ to \\, which results in \.

C:\WINDOWS>dir /b | sed "s/^/%cd:\=\\%\\/" 
C:\WINDOWS\0.log
C:\WINDOWS\003109_.tmp
C:\WINDOWS\addins

barlop

Posted 2012-04-26T17:10:06.457

Reputation: 18 677

0

This is an old question, but I thought I'd add something anyhow.

DIR doesn't traverse correctly all the directory trees you want, in particular not the ones on C:. It simply gives up in places because of different protections.

ATTRIB works much better, because it finds more. (Why this difference? Why would MS make one utility work one way and another work different in this respect? Damned if I know.) In my experience the most effective way to handle this, although it's a kludge, is to get two listings:

attrib /s /d C:\ >%TEMP%\C-with-directories.txt

attrib /s C:\ >%TEMP%\C-without-directories.txt

and get the difference between them. That difference is the directories on C: (except the ones that are too well hidden). For C:, I'd usually do this running as administrator.

djc

Posted 2012-04-26T17:10:06.457

Reputation: 1

0

I wanted to work with a directory listing, so I Googled "Print a Directory". I found instructions to do so, but they included changes to the Registry. Not wanting to diddle with this, and wanting to use a listing, not print it, I found a way to meet my goals without changing the Registry. I created two batch file programs to be saved in a Utility Directory. Then, when I wanted to print or work with a directory, I just copy the appropriate batch file into the subject directory, then execute it! Here they are:

rem PrintThisDirectory.bat
rem Prints the directory where it resides
@echo off
dir %1/-p/o:gn> "%temp%\listing"
start /w notepad "%temp%\listing"

Rem ShowThisDirectory.bat
Rem Displays in Notepad the Directory where it resides
@echo off
dir %1/o:gn> "%temp%\listing"
start /w notepad "%temp%\listing"

Roger Bohl

Posted 2012-04-26T17:10:06.457

Reputation: 1