need help adjust macro a little

T

trend5

need help to customize microsoft code a little:
code sample:

http://support.microsoft.com/?kbid=306248

(this macro just create a list of all files in a specified folder).

I want just adjust this macro a little:

1. set file search for .mp3 and .M3U file types only.

2. no 'File Date/Time' listing required, only file name and size.

3. I need list only file name - without full path specified, i.e.
'Rainbow.mp3'
(Currently macro list full path - C:\Documents and Settings\User\My
Documents\mp3utilities\Rainbow.mp3)

4. I want that the list was numbered( 01, 02...)

5. show file size in Megabytes (i.e. 4,5Mb), not in bytes

thanks.
 
D

Dave Lett

Hi trend,

If you don't need the file size, then you can use the information from the
article "How to read the filenames of all the files in a directory into an
array" at http://word.mvps.org/faqs/macrosvba/ReadFilesIntoArray.htm

You would end up with something like the following:

Dim sPath As String
Dim MyFile As String
Dim Counter As Long

sPath = "c:\test\"
'Create a dynamic array variable, and then declare its initial size
Dim DirectoryListArray() As String
ReDim DirectoryListArray(1000)

'Loop through all the files in the directory by using Dir$ function
MyFile = Dir$(sPath & "*.mp3")
Do While MyFile <> ""
DirectoryListArray(Counter) = MyFile
MyFile = Dir$
Counter = Counter + 1
Loop

'Reset the size of the array without losing its values by using Redim
Preserve
ReDim Preserve DirectoryListArray(Counter - 1)
For Counter = 0 To UBound(DirectoryListArray)
sFileInfo = sFileInfo & Counter + 1 & vbTab
sFileInfo = sFileInfo & DirectoryListArray(Counter) & vbTab
sFileInfo = sFileInfo & FileLen("c:\test\" &
DirectoryListArray(Counter)) / 1000 & vbCrLf
Next Counter
MsgBox sFileInfo

This shows the size of the file in kilobytes (you have to help yourself some
to get it to megabytes). You will need to change the line
MyFile = Dir$(sPath & "*.mp3")
to
MyFile = Dir$(sPath & "*.M3U")
to account for the other file type.

HTH,
Dave
 
T

TANDEX

Dave Lett said:
Hi trend,

If you don't need the file size, then you can use the information from the
article "How to read the filenames of all the files in a directory into an
array" at http://word.mvps.org/faqs/macrosvba/ReadFilesIntoArray.htm

You would end up with something like the following:

Dim sPath As String
Dim MyFile As String
Dim Counter As Long

sPath = "c:\test\"
'Create a dynamic array variable, and then declare its initial size
Dim DirectoryListArray() As String
ReDim DirectoryListArray(1000)

'Loop through all the files in the directory by using Dir$ function
MyFile = Dir$(sPath & "*.mp3")
Do While MyFile <> ""
DirectoryListArray(Counter) = MyFile
MyFile = Dir$
Counter = Counter + 1
Loop

'Reset the size of the array without losing its values by using Redim
Preserve
ReDim Preserve DirectoryListArray(Counter - 1)
For Counter = 0 To UBound(DirectoryListArray)
sFileInfo = sFileInfo & Counter + 1 & vbTab
sFileInfo = sFileInfo & DirectoryListArray(Counter) & vbTab
sFileInfo = sFileInfo & FileLen("c:\test\" &
DirectoryListArray(Counter)) / 1000 & vbCrLf
Next Counter
MsgBox sFileInfo

This shows the size of the file in kilobytes (you have to help yourself
some
to get it to megabytes). You will need to change the line
MyFile = Dir$(sPath & "*.mp3")
to
MyFile = Dir$(sPath & "*.M3U")
to account for the other file type.

HTH,
Dave
---------------------------------

Dave,

I need list 'File name' and 'File size'(in Mb).
Also, how to implement way to retrieve the folder name that the user
selected by calling the standard 'Browse folder dialog'? i.e. implement
integrated browsing capability, to select required folder via browsing, more
easily. Currently code use just input box where exact patch to folder should
be entered manually.
 
D

Dave Lett

Hi,

You can call the Copy File dialog box to allow the user to navigate to a
folder. As for changing from kilobytes to megabytes, have a search on the
Internet or something and do a LITTLE to help yourself.

Dim sPath As String
Dim MyFile As String
Dim Counter As Long
With Dialogs(wdDialogCopyFile)
.Display
sPath = .Directory
End With
'Create a dynamic array variable, and then declare its initial size
Dim DirectoryListArray() As String
ReDim DirectoryListArray(1000)

'Loop through all the files in the directory by using Dir$ function
MyFile = Dir$(sPath & "*.doc")
Do While MyFile <> ""
DirectoryListArray(Counter) = MyFile
MyFile = Dir$
Counter = Counter + 1
Loop

'Reset the size of the array without losing its values by using Redim
Preserve
ReDim Preserve DirectoryListArray(Counter - 1)
For Counter = 0 To UBound(DirectoryListArray)
sFileInfo = sFileInfo & Counter + 1 & vbTab
sFileInfo = sFileInfo & DirectoryListArray(Counter) & vbTab
sFileInfo = sFileInfo & FileLen("c:\test\" &
DirectoryListArray(Counter)) / 1000 & vbCrLf
Next Counter
MsgBox sFileInfo
 
T

TANDEX

Dave Lett said:
Hi,

You can call the Copy File dialog box to allow the user to navigate to a
folder. As for changing from kilobytes to megabytes, have a search on the
Internet or something and do a LITTLE to help yourself.

Dim sPath As String
Dim MyFile As String
Dim Counter As Long
With Dialogs(wdDialogCopyFile)
.Display
sPath = .Directory
End With
'Create a dynamic array variable, and then declare its initial size
Dim DirectoryListArray() As String
ReDim DirectoryListArray(1000)

'Loop through all the files in the directory by using Dir$ function
MyFile = Dir$(sPath & "*.doc")
Do While MyFile <> ""
DirectoryListArray(Counter) = MyFile
MyFile = Dir$
Counter = Counter + 1
Loop

'Reset the size of the array without losing its values by using Redim
Preserve
ReDim Preserve DirectoryListArray(Counter - 1)
For Counter = 0 To UBound(DirectoryListArray)
sFileInfo = sFileInfo & Counter + 1 & vbTab
sFileInfo = sFileInfo & DirectoryListArray(Counter) & vbTab
sFileInfo = sFileInfo & FileLen("c:\test\" &
DirectoryListArray(Counter)) / 1000 & vbCrLf
Next Counter
MsgBox sFileInfo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top