0

So i have been tasked with getting folder and file names for a portable hard drive. Currently I'm not sure how to go about doing this I know the standard command prompt way to go about it, but let's say it's over a million files spread across about 20,000 folders on a terabyte hard drive. So I'm curious if anyone can point me into a starting direction for this. In a nut shell what I would like to do is execute a .bat file that would create a text file with the directory as a header then all files in that folder listed below that directory name but have this cycle through the entire hard drive if this is possible? Or if some one knows if there is a better way to do this, just looking for a direction to start with.

C:/test/folder Alpha
filename112.text
filename221.tif
filename331.gif

C:/test/folder Bravo
filename1.text
filename2.tif
filename3.gif

C:/test/Folder Charlie
filename112.png
filename221.aspx
filename331.jpeg

2 Answers2

0

PowerShell

$LastDirectory = ""
Get-ChildItem -Recurse | ForEach {
    if ($LastDirectory -ne $_.DirectoryName) {
        $LastDirectory = $_.DirectoryName
        Write "`n"
        Write $_.DirectoryName
    }
    Write $_.Name
} | Out-File foundFiles.txt

You can see it on screen by removing the | Out-File foundFiles.txt bit.

TessellatingHeckler
  • 5,726
  • 3
  • 26
  • 44
0

I know this doesn't match your expected output formatting, but a much simpler way to do this is:

dir /s /b /a | sort > files.txt

Output will look like:

C:\test\folder Alpha\
C:\test\folder Alpha\filename112.text
C:\test\folder Alpha\filename221.tif
C:\test\folder Alpha\filename331.gif
C:\test\folder Bravo\
C:\test\folder Bravo\filename1.text
C:\test\folder Bravo\filename2.tif
C:\test\folder Bravo\filename3.gif
C:\test\folder Charlie\
C:\test\Folder Charlie\filename112.png
C:\test\Folder Charlie\filename221.aspx
C:\test\Folder Charlie\filename331.jpeg
notpeter
  • 3,515
  • 2
  • 26
  • 44