0

I am trying to compile a list of all the files in four directories, each with a different path. I have the following code, and it is working, but not how I want it to

@echo off
tree d:\directory > c:\lists\4list.txt /a /f
tree e:\directory2 >> c:\lists\4list.txt /a /f
tree f:\directory3 >> c:\lists\4list.txt /a /f
tree g:\directory4 >> c:\lists\4list.txt /a /f

The output in 4list.txt has all the ASCII characters and spaces at the front of each line. It also has

+---Directory name
    filename1
    filename2
    filename3

listed at each directory in the tree. Is there any way that I can have it generate this list, WITHOUT all the special characters, directory names, spaces, extra lines, AND without the file extensions?

Basically, I am wanting to create this list of the 2200+ files, so I can copy and paste it into an Excel spreadsheet that I have conditional formatting setup on, that highlights duplicate filenames (may have duplicate video files, but with different formats .mkv, .mp4, etc.).

I know that I can manually go through the text file, and using Notepad's find/replace feature, I can "replace" all of the extensions with blank (""), and manually replace the extra characters and spaces at the beginning of each line as well as deleting the "+---Directory" names. However, this can be RATHER time consuming.

I am wanting to create this file, so that it can be scheduled to run once per day, and update the ever growing list of files on these drives.

If there's a way to have this list exported to an Excel document rather than a .txt file that would save me a step or two as well.

  • Would using this PS command help: gci -file "C:\test - copy" -recurse | % {$_.BaseName} to form the start of what you want? – HelpingHand Oct 11 '17 at 7:26
  • It's hard telling what you need exactly but see if a simple DIR /S /B "d:\directory" >> "c:\lists\4list.txt" but otherwise you may need to wrap that command in a FOR /F loop and then ECHO %~NA using substitutions to get just the file name portion of each value from the DIR command to only show the file name without the extension of the rest of the folder path each file resides. – Pimp Juice IT Oct 15 '17 at 4:55
0

This link seems like it will help you. http://windowsitpro.com/scripting/build-directory-tree-structure-reports

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.