views:

1566

answers:

6

Hi I would like to recieve the following output -

Suppose the directory structure on the file system is like this:

  -dir1
      -dir2
     -file1
     -file2
       -dir3
       -file3
       -file4
      -dir4
       -file5
       -dir5
       -dir6
       -dir7

The output from the script must be like:

Directories:

/dir1
/dir1/dir2
/dir1/dir2/dir3
/dir1/dir2/dir4
/dir1/dir5
/dir1/dir5/dir6
/dir1/dir5/dir7

Files:

/dir1
/dir1/dir2/file1
/dir1/dir2/file2
/dir1/dir2/dir3/file3
/dir1/dir2/dir3/file4
/dir1/dir2/dir4/file5
/dir1/dir5/dir6
/dir1/dir5/dir7

Hi could you guys tell me how to keep the output of "find . -type d" and "find . -type f" into another file.. thanks a lot guys

+2  A: 

Bash/Linux Shell

Directories:

find ./ -type d

Files:

find ./ -type f

Bash/Shell Into a file

Directories:

find ./ -type d  > somefile.txt

Files:

find ./ -type f  > somefile.txt
Kent Fredric
+4  A: 

in shell:

find . -type d

gives directories from current working directory, and:

find . -type f

gives files from current working directory.

Replace . by your directory of interest.

mouviciel
A: 

In Windows :

dir /ad /b /s

dir /a-d /b /s

Peter
+3  A: 

In windows, to list only directories:

dir /ad /b /s

to list all files (and no directories)

dir /a-d /b /s

redirect the output to a file by adding (without quotes)

'> filename.txt'
Andrea Bertani
A: 

In Linux, a simple

find . -printf '%y %p\n'

will give you a list of all the contained items, with directories and files mixed. You can save this output to a temporary file, then extract all lines that start with 'd'; those will be the directories. Lines that start with an 'f' are files.

unwind
A: 

On Windows, you can do it like this as most flexibile solution that allows you to additionally process dir names.

You use FOR /R to recursively execute batch commands.

Check out this batch file.

@echo off
SETLOCAL EnableDelayedExpansion

SET N=0
for /R %%i in (.) do (
     SET DIR=%%i

     ::put anything here, for instance the following code add dir numbers.
     SET /A N=!N!+1
     echo !N! !DIR!
)

Similary for files you can add pattern as a set instead of dot, in your case

 (*.*)
majkinetor