Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Command to list all files in a folder as well as sub-folders
#1
Hey guys I have been looking all day to find a command which will list all files on a drive including files in  sub folders and save the list to a file.
I create a .bat file from notepad with these instructions and run the bat file from the root of the drive which contains the files and sub folders.

dir /b /s /a:-d  >list.txt

I get a file called list.txt with entries like this

E:\New Movies\The file test.mp4

But I would like to just have it list like this

The file test.mp4

I dont need to know the directories, file only. and for some reason when run on an external hard drive It picks up the recycled folder like this,

E:\$RECYCLE.BIN\S-1-5-21-2095992690-2580178275-4034271705-1001\$I3EZY6W.avi

I want to scrub that out as well.

Cheers for any help.
Reply

#2
Try this:

  1. Copy all code below. 
  2. Paste to notepad and Create a vbs file ie: list.vbs
  3. Change directory location GetFiles("YOUR LOCATION") to wherever you want. Example: GetFiles("E:\Downloads")
  4. Right Click list.vbs and open in command prompt
  5. It will create a OutputFiles.csv in the directory you run list.vbs
Code:
Dim fso
Dim ObjOutFile

Set fso = CreateObject("Scripting.FileSystemObject")

Set ObjOutFile = fso.CreateTextFile("OutputFiles.csv")

ObjOutFile.WriteLine("Type,File Name,File Path")

GetFiles("YOUR LOCATION")

ObjOutFile.Close

WScript.Echo("Completed")

Function GetFiles(FolderName)
   On Error Resume Next

   Dim ObjFolder
   Dim ObjSubFolders
   Dim ObjSubFolder
   Dim ObjFiles
   Dim ObjFile

   Set ObjFolder = fso.GetFolder(FolderName)
   Set ObjFiles = ObjFolder.Files

   For Each ObjFile In ObjFiles
   ObjOutFile.WriteLine("File," & ObjFile.Name & "," & ObjFile.Path)
   Next

   Set ObjSubFolders = ObjFolder.SubFolders

   For Each ObjFolder In ObjSubFolders

       ObjOutFile.WriteLine("Folder," & ObjFolder.Name & "," & ObjFolder.Path)


       GetFiles(ObjFolder.Path)
   Next

End Function
<left><form action="https://www.paypal.com/cgi-bin/webscr" method="post">If you are satisfied with my help, consider a donation. Thank you so much for your continued support! 
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="Y4ZDLXGFS4F8Q">
<input type="image" src="https://www.paypalobjects.com/en_US/GB/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal — The safer, easier way to pay online.">
<img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="0" height="0">
</form>

   </div></left> 
Reply

#3
(07-02-2016, 12:42 PM)Britec Wrote:  Try this:



  1. Copy all code below. 
  2. Paste to notepad and Create a vbs file ie: list.vbs
  3. Change directory location GetFiles("YOUR LOCATION") to wherever you want. Example: GetFiles("E:\Downloads")
  4. Right Click list.vbs and open in command prompt
  5. It will create a OutputFiles.csv in the directory you run list.vbs
Code:
Dim fso
Dim ObjOutFile

Set fso = CreateObject("Scripting.FileSystemObject")

Set ObjOutFile = fso.CreateTextFile("OutputFiles.csv")

ObjOutFile.WriteLine("Type,File Name,File Path")

GetFiles("YOUR LOCATION")

ObjOutFile.Close

WScript.Echo("Completed")

Function GetFiles(FolderName)
   On Error Resume Next

   Dim ObjFolder
   Dim ObjSubFolders
   Dim ObjSubFolder
   Dim ObjFiles
   Dim ObjFile

   Set ObjFolder = fso.GetFolder(FolderName)
   Set ObjFiles = ObjFolder.Files

   For Each ObjFile In ObjFiles
   ObjOutFile.WriteLine("File," & ObjFile.Name & "," & ObjFile.Path)
   Next

   Set ObjSubFolders = ObjFolder.SubFolders

   For Each ObjFolder In ObjSubFolders

       ObjOutFile.WriteLine("Folder," & ObjFolder.Name & "," & ObjFolder.Path)


       GetFiles(ObjFolder.Path)
   Next

End Function

Did this work for you mate? I guess you would have tried it, it created a file but only 1 entry in it.
Thanks for the help mate.
Reply

#4
Yeah it works
<left><form action="https://www.paypal.com/cgi-bin/webscr" method="post">If you are satisfied with my help, consider a donation. Thank you so much for your continued support! 
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="Y4ZDLXGFS4F8Q">
<input type="image" src="https://www.paypalobjects.com/en_US/GB/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal — The safer, easier way to pay online.">
<img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="0" height="0">
</form>

   </div></left> 
Reply

#5
(07-03-2016, 09:54 PM)Britec Wrote:  Yeah it works

And works brilliantly I might add, and lightning fast really incredible!

Is there any way to just list the file without the location and just search for .avi/.mp4/

Brilliant job mate.
Reply

#6
Nah not with that script, glad it works for you.
<left><form action="https://www.paypal.com/cgi-bin/webscr" method="post">If you are satisfied with my help, consider a donation. Thank you so much for your continued support! 
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="Y4ZDLXGFS4F8Q">
<input type="image" src="https://www.paypalobjects.com/en_US/GB/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal — The safer, easier way to pay online.">
<img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="0" height="0">
</form>

   </div></left> 
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

Powered By MyBB, © 2002-2024 Melroy van den Berg.