PDA

View Full Version : List Directory Structure to a CSV



Ed Jobe
2023-06-16, 08:44 PM
Does anyone have a lisp or bat that can allow a user to select a folder and then output the tree structure to a csv or xlsx?

Thanks in advance.

Ed Jobe
2023-06-16, 11:05 PM
I found a way to import a tree structure into Excel, using Excel. It’s a few more steps than dos tree, but the results are a lot cleaner and sortable. When you run the first query, the Query palette displays or you can click on Data>Show Queries.


Open a new spreadsheet.
On the Data ribbon tab, select Get and Transform panel >New Query>From File>From Folder.
Browse to the folder to import and select OK.
This opens a preview of the query results.
If you want to change the columns shown or edit the query, click on the Edit button. This opens Power Query Editor tool.


Select the columns to show. You can drag to change their order.


Click on Close and Load.
For other folder imports, you can click on the query and select Edit.


Then you can click on the Advanced Query
Edit the path to the main folder.
Optionally, you can rename the table name.
Click on Done and you back to step 6.
Save As to save to a different folder.

peter
2023-06-17, 04:40 PM
Ed... There are multiple ways to get a list to a .csv file.

But just getting the folder tree


;___________________________________________________________________________________________________________|
;
; Written By: Peter Jamtgaard copyright 2023 All Rights Reserved
;___________________________________________________________________________________________________________|

; Abstract: This function when give a root folder will get the folder tree under it and return as a list.

;___________________________________________________________________________________________________________|
;
; General Function Header List
;___________________________________________________________________________________________________________|

; Function List Argument1 Argument2 Arguement3
;* (FolderSearch strFolder)
;* Function to search for sub folder tree

;* (subFolderSearchRecursion (strFolder)
;* Recursive function to find folders in a tree.


;$ End Header

;___________________________________________________________________________________________________________|
;
; Recursive Function for Searching for a (WC) file and returns a list of strings.
;___________________________________________________________________________________________________________|

(defun FolderSearch (strFolder
/
lstReturn
subFileSearchRecursion
strSubFolder
)

(defun subFolderSearchRecursion (strFolder / strSubFolder)
(foreach strSubFolder (vl-directory-files strFolder nil -1)
(if (and (/= strSubFolder ".")
(/= strSubFolder "..")
(setq strFullFolder (strcat strFolder strSubFolder))
(setq lstReturn (cons strFullFolder lstReturn))
)
(subFolderSearchRecursion (strcat strFolder strSubFolder "\\"))
)
)
)
(if (/= (car (reverse (vl-string->list strFolder))) 92)
(setq strFolder (strcat strFolder "\\"))
)
(setq lstReturn (list strFolder))
(subFolderSearchRecursion strFolder)
(reverse lstReturn)
)

(princ "!")
(vl-load-com)

BIG-AL
2023-06-20, 03:10 AM
If your like me old fashioned DOS does it. Makes a text file for you. The /s is do subdirectories the /b is a shorter listing of files etc.

You go to Windows lower left
CMD
then you need to change to the top level of the directory eg
CD myprojects
Then can get all directory info like all files or a simple tree
dir *. > c:\mytempdir\Tree.txt /b

dir *.dwg c:\mytempdir\dwgs.txt /b /s
This takes a little while as I had way to many dwg's 13,000+

Interesting in my \Autodesk some 2500 dwg's not made by me. Some 160 CIV3D tutorial dwg's.

I may use this to free up some space. Convert the txt to a batch file and delete.

Osama.Omari
2023-06-20, 06:12 PM
create a text file and paste this command line:

dir /q /r /s /b /4 /a-d *.* >List_files.txt

Then change the extension to .bat now when you run that batch file it will create a text file list_files.txt (you can change the file name) contain all the folders and its subfolders and the files they contain.

Ed Jobe
2023-06-20, 06:18 PM
Thanks everyone. What I needed was specific information that the xl solution provided. Either in the form of Folder>Folder>File or like the spreadsheet did, Column1=Path, Column2=File. The format that DIR and TREE use wasn't going to work for the xl template I needed.

Osama.Omari
2023-06-20, 06:45 PM
open the file you create that contains the folders and subfolders and its files name in excel and split them by the backslash. and you will get what you want.

Ed Jobe
2023-06-21, 03:09 PM
open the file you create that contains the folders and subfolders and its files name in excel and split them by the backslash. and you will get what you want.

No need. The query process I mentioned above does it automatically. No extra processing required.