Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...I also believe that we all can contribute to each other's growth by sharing knowlege and experiences. I would love to take my skills and help people around the world solve problems..."

Geography

Where in the world do Tek-Tips members come from?
wasserfa89 (TechnicalUser)
11 Jun 12 10:03
Hi all
I use Visual Basic 2010 Express and the Code below
-------------------------------------------------------
Module Module1
Dim fln, result ' Declare Variables
Dim fname As String
' Freespace
' Shows Space Usage of every Folder on the fileserver


Sub Main()
fname = "c:\temp\test.txt"
fln = FileLen(Trim(fname))
result = CInt((fln / 1024) / 1024) & " MB" & "(" & fln & "BYTES)"
MsgBox("Grösse des Files --> " & result)
End Sub

End Module
--------------------------------------------------------
so far so good, Script works fine, but now i need the following:

How can read out recursivly a path for example

Drive D:\

and list file Size of every folder recursivly

The idea behind is a little statistic tool which shows the consumption of the disk space on the fileserver

Thanks for your helfp
Kliot (Programmer)
12 Jun 12 15:13
You can use DirectoryInfo to loop through all the files on the drive and get info about each file and directory.


CODE

Imports System.IO

Dim dDir As DirectoryInfo
dDir = New DirectoryInfo("D:\")

For Each fFileSystemInfo In dDir.GetFiles("*.*", SearchOption.AllDirectories)

'fFileSystemInfo.DirectoryName
'fFileSystemInfo.Length
'fFileSystemInfo.Name

Next
wasserfa89 (TechnicalUser)
14 Jun 12 2:55
ok thanks works fine

and how can i print out the results with a MSGBox or so?

buzzwang (Programmer)
28 Jun 12 12:05
I would guess something like:

CODE

MsgBox("Name: " & fFileSystemInfo.DirectoryName & vbcrlf & "Length: " & fFileSystemInfo.Length & vbcrlf & etc. etc. ) 

Obviously I haven't checked that, but I think you get the gist of the idea. Though instead of using a message box, perhaps a multi-line textbox would be better? then you could scroll through it afterwards and read it all, copy/paste the info, etc.

If memory serves me, something like:

CODE

textbox1.text = textbox1.text & vbcrlf & "Name: " & fFileSystemInfo.DirectoryName & vbcrlf & "Length: " & fFileSystemInfo.Length & vbcrlf & etc. etc. 

That'll append new info to the existing contents of the textbox. Or you could just use TextBox.AppnedText instead (I just remembered that).

In fact...

CODE

Private Sub SetText([text] As String)
        ' InvokeRequired compares the thread ID of the
        ' calling thread to the thread ID of the creating thread.
        ' If these threads are different, it returns true and fires, Else not.
        Try
            If Me.txt_folderactivity.InvokeRequired Then
                'Dim d As New SetTextCallback(AddressOf SetText)
                'Me.Invoke(d, New Object() {[text]})
                Me.txt_folderactivity.Invoke(New SetTextCallback(AddressOf SetText), [text])
            Else
                'Me.txt_folderactivity.Text &= [text]
                Me.txt_folderactivity.AppendText([text])
                Me.txt_folderactivity.SelectionStart = txt_folderactivity.Text.Length
                Me.txt_folderactivity.ScrollToCaret()
            End If
        Catch ex As Exception
            Me.txt_folderactivity.AppendText(ex.Message & vbCrLf)
        End Try
    End Sub
Private Sub scrollTextDel()
        'txt_folderactivity.SelectionLength = 0
        txt_folderactivity.SelectionStart = txt_folderactivity.Text.Length
        txt_folderactivity.ScrollToCaret()
    End Sub
 Private Sub scrollText()
        myDel = New scrollTextCallback(AddressOf scrollTextDel)
    End Sub 

I used that a few months back and forgot about it. You'd use it something like: SetText("File " & e.FullPath & " has been created.") and calling ScrollText() would make sure that the newest info was always visible by scrolling the multi-line textbox to the bottom. So I would call that after adding line to the box to keep the newest info visible all the time.

Each time you use SetText it puts whatever info/text on a new line in the textbox. I had to figure this out because I was trying to write to a textbox from another thread and was getting invoke errors about it. SetText gets me around the invoke problem. The program this came from watches a folder on the hard drive, and when files of a certain name or type/extension are created, it starts doing things with them. In my case, it watches for files from my TiVo and converts them to MPG and then moves that new file to a different folder. The textbox was named txt_folderactivity.


Hopefully this'll help or maybe get you on the right track or something. If I wasted your time then I apologize.


____________
Buzzwang
"I can fix it!"
(maybe...)

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close