?
Solved

How can I find the size of a file from the programme

Posted on 2005-04-06
9
Medium Priority
?
190 Views
Last Modified: 2010-04-23
I run a programme and it creates a file and I'm calling other procedures based on the file creation. I know how to check whether the file is created or not  BUT I WANT TO KNOW THE FILE SIZE. IF THE FILE SIZE IS 1KB I DON'T WANT TO CALL ANY PROCEDURES FURTHER OTHERWISE I WANT TO. How to determine the file size which is sitting in one of my directories.

Thanks
vm
0
Comment
Question by:vmandem
9 Comments
 
LVL 12

Accepted Solution

by:
S-Twilley earned 80 total points
ID: 13719876

to determine whether a file is present... use

If IO.File.Exists(myFilename) Then

Else

End If

--------

alternatively, you could cover file size and existence together:

        Dim fiThisFile As New IO.FileInfo(myFileName)

        If fiThisFile.Exists Then
            If fiThisFile.Length > 1024 Then

            End If
        End If

==========

Im hoping i got that right
0
 
LVL 12

Expert Comment

by:S-Twilley
ID: 13719895
you can also use the FileLen function

Dim fLength As Integer = FileLen(myFileName)
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 13719897
Imports System.IO

Public Class IO_Library

  Public Shared Function FileSize(ByVal path As String) As Integer

    Dim info As New FileInfo(path)

    Return info.Length

  End Function 'FileSize'

End Class 'IO_Library'


Usage:
Dim size As Integer = IO_Library.FileSize(path)

Bob
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 96

Expert Comment

by:Bob Learned
ID: 13719903
Ooh, too slow :(

Bob
0
 
LVL 12

Expert Comment

by:S-Twilley
ID: 13719930
I know the feeling... went to sleep for a few hours and all the good (well.. the questions I can answer) have all passed me by!
0
 

Expert Comment

by:pavlosgr
ID: 13720013

Dim filename as string
Dim fi As IO.FileInfo

filename="YourFileName"
fi=new IO.FileInfo(filename)
MessageBox.Show(fi.Length.ToString)


fi.Length contains the file size  in bytes.

Hope this help
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 13720049
"Another rides the bus, and another one's on, and another one's on..."  :)

Bob
0
 
LVL 12

Expert Comment

by:S-Twilley
ID: 13720052
I think there's an echo on this thread :P
0
 

Author Comment

by:vmandem
ID: 13720271
I thank every one for overwhelming responses. I Love EE.

Thanks Again.
vm
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month14 days, 17 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question