Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 12-07-2010
Member
 
Join Date: Jul 2010
Posts: 2
Windows Batch file to output directory names and size to txt file

I have my movies arranged such that each movie has its own folder.

Like this:

>Movies
>>The Boondock Saints (1999)
>>>the.boondock.saints.mkv
>>>folder.jpg
>>The Matrix (1999)
>>>matrix.mkv
>>>folder.jpg

I want to make a batch file to output the movie folder name and the size of the directory (preferably in Mb)

I know that if i do dir d:\movies /b >movies.txt i can get the folder names but i want the text document to be in this format:

The Boondock Saints (1999) 4700Mb (i dont need the Mb there)
The Matrix (1999) 4700Mb

Can anyone help?
Reply With Quote
  #2  
Old 13-07-2010
Member
 
Join Date: Jan 2006
Posts: 605
Re: Windows Batch file to output directory names and size to txt file

I have heard about a small bat file created by Jon from theHTPC.net that can be placed in your unsorted movie folder and used to automatically sort all those movies into the proper folder structure. Any of the extras you might have such as subtitle files will even come along. Download the bat file from here and extract it in the movie directory that needs sorted out.

As for getting rid of the MB, you will need something that can be viewable in icons list or tiles views which I am afraid where to get one of this things for.
Reply With Quote
  #3  
Old 13-07-2010
Member
 
Join Date: Jul 2010
Posts: 2
Re: Windows Batch file to output directory names and size to txt file

Thanks Janos™, but this isn't quite what I'm looking for... My movie folder is already organized the way I want it. What I want to do is make a script that will list the name, year, and size of each movie so that I can then turn it into a .CSV file.
Reply With Quote
  #4  
Old 13-07-2010
Member
 
Join Date: Dec 2007
Posts: 1,728
Re: Windows Batch file to output directory names and size to txt file

Ok, so you want to make a movie database if I am getting you correctly or am I? In that case try downloading a software called Movie Collector which is a movie database software to catalog your collection of DVDs, DivX files, VHS tapes, etc... Adding movies to the database is quick and easy, no typing needed. Just type the movie title and Movie Collector will automatically download all information from various sources on the internet (like IMDb and DVD Empire), including the cover image.
Reply With Quote
  #5  
Old 13-07-2010
Member
 
Join Date: Jul 2010
Posts: 1
Re: Windows Batch file to output directory names and size to txt file

I've got the same problem.
and I want to get some help from the internet
Reply With Quote
  #6  
Old 14-07-2010
Member
 
Join Date: Apr 2008
Posts: 1,948
Re: Windows Batch file to output directory names and size to txt file

Quote:
Originally Posted by masakas View Post
I've got the same problem.
and I want to get some help from the internet
Could you please specify your problem in detail? Usually coming here and asking for help without giving proper details will only fetch you assumptions made by us. Upon searching, I have found that the below will do what you want in an excel sheet. Add it as a macro to your sheet, when run it will create a sheet with all the information that you require.

Code:
Public X() 
Public i As Long 
Public objShell, objFolder, objFolderItem 
Public FSO, oFolder, Fil 

Sub MainExtractData() 

Dim NewSht As Worksheet 
Dim MainFolderName As String 
Dim TimeLimit As Long, StartTime As Double 

ReDim X(1 To 65536, 1 To 11) 

Set objShell = CreateObject("Shell.Application") 
TimeLimit = Application.InputBox("Please enter the maximum time that you wish this code to run for in minutes" & vbNewLine & vbNewLine & _ 
"Leave this at zero for unlimited runtime", "Time Check box", 0) 
StartTime = Timer 

' This is the part I need to change to create a Table with these field names. 

Application.ScreenUpdating = False 
MainFolderName = BrowseForFolder() 
Set NewSht = ThisWorkbook.Sheets.Add 

X(1, 1) = "Path" 
X(1, 2) = "File Name" 
X(1, 3) = "Last Accessed" 
X(1, 4) = "Last Modified" 
X(1, 5) = "Created" 
X(1, 6) = "Type" 
X(1, 7) = "Size" 
X(1, 8) = "Owner" 
X(1, 9) = "Author" 
X(1, 10) = "Title" 
X(1, 11) = "Comments" 

' i is defined Publicly as a Long Integer 
i = 1 

Set FSO = CreateObject("scripting.FileSystemObject") 
Set oFolder = FSO.GetFolder(MainFolderName) 
'error handling to stop the obscure error that occurs at time when retrieving DateLastAccessed 
On Error Resume Next 
For Each Fil In oFolder.Files 
Set objFolder = objShell.Namespace(oFolder.Path) 
Set objFolderItem = objFolder.ParseName(Fil.Name) 
i = i + 1 
If i Mod 20 = 0 And TimeLimit <> 0 And Timer > (TimeLimit * 60 + StartTime) Then 
GoTo FastExit 
End If 
If i Mod 50 = 0 Then 
Application.StatusBar = "Processing File " & i 
DoEvents 
End If 
X(i, 1) = oFolder.Path 
X(i, 2) = Fil.Name 
X(i, 3) = Fil.DateLastAccessed 
X(i, 4) = Fil.DateLastModified 
X(i, 5) = Fil.DateCreated 
X(i, 6) = Fil.Type 
X(i, 7) = Fil.Size 
X(i, 8) = objFolder.GetDetailsOf(objFolderItem, 8) 
X(i, 9) = objFolder.GetDetailsOf(objFolderItem, 9) 
X(i, 10) = objFolder.GetDetailsOf(objFolderItem, 10) 
X(i, 11) = objFolder.GetDetailsOf(objFolderItem, 14) 
Next 

'Get subdirectories 
If TimeLimit = 0 Then 
Call RecursiveFolder(oFolder, 0) 
Else 
If Timer < (TimeLimit * 60 + StartTime) Then Call RecursiveFolder(oFolder, TimeLimit * 60 + StartTime) 
End If 

FastExit: 
Range("A:K") = X 
If i < 65535 Then Range(Cells(i + 1, "A"), Cells(65536, "A")).EntireRow.Delete 
Range("A:K").WrapText = False 
Range("A:K").EntireColumn.AutoFit 
Range("1:1").Font.Bold = True 
Rows("2:2").Select 
ActiveWindow.FreezePanes = True 
Range("a1").Activate 

Set FSO = Nothing 
Set objShell = Nothing 
Set oFolder = Nothing 
Set objFolder = Nothing 
Set objFolderItem = Nothing 
Set Fil = Nothing 
Application.StatusBar = "" 
Application.ScreenUpdating = True 
End Sub 

Sub RecursiveFolder(xFolder, TimeTest As Long) 
Dim SubFld 
For Each SubFld In xFolder.SubFolders 
Set oFolder = FSO.GetFolder(SubFld) 
Set objFolder = objShell.Namespace(SubFld.Path) 
For Each Fil In SubFld.Files 
Set objFolder = objShell.Namespace(oFolder.Path) 
'Problem with objFolder at times 
If Not objFolder Is Nothing Then 
Set objFolderItem = objFolder.ParseName(Fil.Name) 
i = i + 1 
If i Mod 20 = 0 And TimeTest <> 0 And Timer > TimeTest Then 
Exit Sub 
End If 
If i Mod 50 = 0 Then 
Application.StatusBar = "Processing File " & i 
DoEvents 
End If 
X(i, 1) = SubFld.Path 
X(i, 2) = Fil.Name 
X(i, 3) = Fil.DateLastAccessed 
X(i, 4) = Fil.DateLastModified 
X(i, 5) = Fil.DateCreated 
X(i, 6) = Fil.Type 
X(i, 7) = Fil.Size 
X(i, 8) = objFolder.GetDetailsOf(objFolderItem, 8) 
X(i, 9) = objFolder.GetDetailsOf(objFolderItem, 9) 
X(i, 10) = objFolder.GetDetailsOf(objFolderItem, 10) 
X(i, 11) = objFolder.GetDetailsOf(objFolderItem, 14) 
Else 
Debug.Print Fil.Path & " " & Fil.Name 
End If 
Next 
Call RecursiveFolder(SubFld, TimeTest) 
Next 
End Sub 

Function BrowseForFolder(Optional OpenAt As Variant) As Variant 
'Function purpose: To Browser for a user selected folder. 
'If the "OpenAt" path is provided, open the browser at that directory 
'NOTE: If invalid, it will open at the Desktop level 

Dim ShellApp As Object 

'Create a file browser window at the default folder 
Set ShellApp = CreateObject("Shell.Application"). _ 
BrowseForFolder(0, "Please choose a folder", 0, OpenAt) 

'Set the folder to that selected. (On error in case cancelled) 
On Error Resume Next 
BrowseForFolder = ShellApp.self.Path 
On Error GoTo 0 

'Destroy the Shell Application 
Set ShellApp = Nothing 

'Check for invalid or non-entries and send to the Invalid error 
'handler if found 
'Valid selections can begin L: (where L is a letter) or 
'\\ (as in \\servername\sharename. All others are invalid 
Select Case Mid(BrowseForFolder, 2, 1) 
Case Is = ":" 
If Left(BrowseForFolder, 1) = ":" Then GoTo Invalid 
Case Is = "\" 
If Not Left(BrowseForFolder, 1) = "\" Then GoTo Invalid 
Case Else 
GoTo Invalid 
End Select 

Exit Function 

Invalid: 
'If it was determined that the selection was invalid, set to False 
BrowseForFolder = False 

End Function
Reply With Quote
  #7  
Old 16-07-2010
Member
 
Join Date: Dec 2009
Posts: 23
Re: Windows Batch file to output directory names and size to txt file

I assume you want to start in /Movies folder, list the name of each subfolder, and list the size of the .mkv file within that subfolder.

This script will work.


Code:
# Script ListMovies.txt
var string list, subfolder, moviename., moviesize
# Go to the /Movies directory.
cd "/Movies"
# Create a list of all subfolders.
lf -n "*" "." (ftype=="d") > $list
# Go thru subfolders, one at a time.
while ($list <> "")
do
    # Get the next subfolder.
    lex "1" $list > $subfolder
    # Get the movie name
    stex -p "^/^l[" $subfolder > $moviename
    # Get the size of the file $subfolder/*.mkv
    lf -s ($subfolder+"/*.mkv") > $moviesize
    # List $moviename and $moviesize
    echo $moviename " " $moviesize
done

This is biterscripting script. Save the code in file C:/Scripts/ListMovies.txt. Run it with command

Code:
script "C:/Scripts/ListMovies.txt"
Should do the trick.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Windows Batch file to output directory names and size to txt file"
Thread Thread Starter Forum Replies Last Post
Windows batch file: set output of program to a variable? supernoob Windows Software 5 17-10-2010 05:58 AM
Batch file to check directory Trini Alvarado Software Development 5 01-04-2010 11:00 AM
Dos batch file to sort files based on file names. Jon Osborn Windows Server Help 9 17-06-2009 11:06 AM
Is it possible to right click on cmd batch file and try to open it in a directory Kamran Operating Systems 2 26-05-2009 10:41 AM
Batch file to create directory with a date in Windows 2003 Aadimoolan Window 2000 Help 2 16-11-2007 02:55 AM


All times are GMT +5.5. The time now is 08:54 AM.