How can I export a directory structure in Windows?

808

Solution 1

Assuming your directory tree is of reasonable size, you could also use the built in tree command, which produces a rather pretty looking directory tree. Unfortunately this prettiness is difficult to get working outside of a cmd instance, so you'll probably want to tell it to just use ascii characters with the /A switch.

Example:

From a small multi-level structure

+---A
|   +---A
|   \---B
+---B
|   \---A
|       \---A
\---C

You can then redirect this to a file using a command like:

tree /A ["directory path"] > tree.txt

Where the directory path is optional, but useful if you want to tree something which isn't the current working directory.

Solution 2

If you want to use the code is very simple and the output is nice.

Code:

Get-ChildItem | tree

With

Get-ChildItem | tree > foo.txt

you can pipe the output to a Textfile.

Example Output:

Auflistung der Ordnerpfade für Volume System
Volumeseriennummer : 48E9-F43B
C:.
├───Contacts
├───Desktop
├───Downloads
│   └───Evernote Import
├───Dropbox
│   ├───Apps
│   │   └───iftttcom
│   │       └───getpocketpdf
│   ├───Backup
│   ├───Camera Uploads
│   ├───Development

Solution 3

You can also put the results directly into the clipboard (in Vista+):

tree | clip

Solution 4

While you most likely want the output of the TREE command (e.g. TREE /F > output.txt) in this case, if raw text as the output is fine, then you can run the following from a command prompt:

DIR C:\ /S > output.txt

Where output.txt will be generated in the current working directory, and contain a listing of all files and directories on the C: drive. If you want just an output of files with their full paths, run the following:

DIR C:\ /B /S > output.txt

It would also be a trivial task to write a program to parse the output back into a directory view style program for you to view.

Solution 5

Open command prompt window --> Go to your directory path

Then run the following command to generate

tree /f /a > tree.doc

Above command will make the folder and files structure recursively and export to word document file. You can find "tree.doc" created in the same folder

Share:
808

Related videos on Youtube

johnw182
Author by

johnw182

Updated on September 17, 2022

Comments

  • johnw182
    johnw182 almost 2 years

    I have a PreferenceFragment that loads preferences by calling addPreferencesFromResource(R.xml.preferences_main);

    In side the preferences_main.xml file I have a custom preference called TimePreference which extends DialogPreference. TimePreference contains nothing but a TimePicker (have also tried DatePicker). When displayed the TimePicker is now a different format. Instead of being a spinner, it is the version with EditText views and up/down arrows. The real problem is those arrows are white and the text is white, all on a white background dialog.

    If I put a TimePicker on an activity, it is the themed spinner style.

    I cannot find out why this only happens on a DialogPreference and not on the activity. Its like it loses all styling.

    My base theme is Theme.AppCompat.Light, I have tried a couple others with the same result.

    Edit: My minSdkVersion is 11 and the target is 19

    Anyone have any ideas?

    public class TestPreference extends DialogPreference {
    
    Button btn;
    TimePicker tp;
    
    public TestPreference(Context context, AttributeSet attrs) {
        super(context, attrs);
        // TODO Auto-generated constructor stub
    }
    
    @Override
    protected View onCreateDialogView() {
        tp = new TimePicker(getContext().getApplicationContext());
        return tp;
    }
    

    }

    TimePicker in DialogPreference

    • Admin
      Admin about 13 years
    • Admin
      Admin almost 13 years
      If you want, I can write an AutoIt script to export the directory listing into plain-text in whatever style you would like. You could then write a program to parse it back into a directory-view like style.
    • Admin
      Admin over 9 years
      Related question at Stack Overflow.
  • xan
    xan almost 13 years
    You can also pipe this output to a text file by doing: tree E: \A \F > output.txt
  • UNK
    UNK almost 13 years
    @xan; Whoops, that was the important bit of the answer and I completely forgot about it! Thanks
  • Breakthrough
    Breakthrough almost 13 years
    @xan just FYI, you need to use forward-slashes (/) instead of backslashes for command line argument identifiers. Backslashes are directory tree separators in Windows systems.
  • Rick Methe
    Rick Methe over 10 years
    There seems to be a (small) limit to how much this can print. It stops part way through my files.
  • johnw182
    johnw182 almost 10 years
    I was just trying that before eclipse crashed and it seemed to be working. I will let you know more in a few.
  • johnw182
    johnw182 almost 10 years
    Also TestPreference is being created from the preferences xml so how can I pass my activity's reference to it?
  • waqaslam
    waqaslam almost 10 years
    ahh, then simply stick to what I said for initializing TimePicker.
  • johnw182
    johnw182 almost 10 years
    waqaslam, that was the solution... The style was still different that the norm and that was because the style in values-14 was different. I changed that style and got the expected layout. The issue with the font and arrows being white was resolved by removing the .getApplicationContext(). Thanks!
  • eddy
    eddy almost 10 years
    Thank you so much! You're a lifesaver. @waqaslam do you think you could help me here goo.gl/MAjgTh
  • Ulysses Alves
    Ulysses Alves over 7 years
    You can also show the filenames below their parent folder on the tree structure by adding the /f option like this: tree /A /f ["directory path"] > tree.txt
  • Royi
    Royi about 7 years
    Could one control the depth of the tree?
  • I say Reinstate Monica
    I say Reinstate Monica over 5 years
    @Royi I see you've posted several comments asking follow up questions. Please post your own question instead. Link back to this post to provide context if needed.
  • Royi
    Royi over 4 years
    Can you limit it to folders name and limit the depth to 2?
  • Avsek
    Avsek over 4 years
    Yes, you can. Get-ChildItem -Recurse -Directory -Depth 2 'Z:\temp' | Select-Object -Property FullName,name | Export-Csv directory_structure.csv
  • Tolga
    Tolga about 4 years
    I'm afraid tree discards the input from the pipeline. For that reason your command is the same as running tree by itself, so it is pointless to pipe the output of Get-ChildItem to tree.
  • Grumpy ol' Bear
    Grumpy ol' Bear almost 4 years
    Could someone build this pretty please? It does exactly what I want.
  • Anmol Singh Jaggi
    Anmol Singh Jaggi almost 4 years
    @Grumpyol'Bear If you want, I can port it to Python this weekend :)
  • Kamlesh
    Kamlesh over 3 years
    just goto the directory you want to export in command line then enter this command: dir /b /s > exported_files.txt