?
Solved

How do I read a file's Properties

Posted on 1999-01-06
5
Medium Priority
?
208 Views
Last Modified: 2008-03-06
What I need to do is look at all of the files (Excell, PowerPoint...) in a certain location, compare their properties (name, size, date created) with the files I already have, and, if I don't have that file already, copy the file to a new location.

I need to know how to read the files properties, and also how to copy the file to another location.
0
Comment
Question by:carla1
  • 2
  • 2
5 Comments
 

Author Comment

by:carla1
ID: 1454404
Edited text of question
0
 
LVL 2

Expert Comment

by:trillo
ID: 1454405
You can use API's.
You can retrieve the Files properties using "GetFileAttributes" function.
If the function succeeds, the return value contains the attributes of the specified file or directory.
If the function fails, the return value is 0xFFFFFFFF. To get extended error information, call GetLastError.
The attributes can be one or more of the following values:
FILE_ATTRIBUTE_ARCHIVE      The file or directory is an archive file or directory. Applications use this flag to mark files for backup or removal.
FILE_ATTRIBUTE_COMPRESSED      The file or directory is compressed. For a file, this means that all of the data in the file is compressed. For a directory, this means that compression is the default for newly created files and subdirectories.
FILE_ATTRIBUTE_DIRECTORY      The "file or directory" is a directory.
FILE_ATTRIBUTE_HIDDEN      The file or directory is hidden. It is not included in an ordinary directory listing.
FILE_ATTRIBUTE_NORMAL      The file or directory has no other attributes set. This attribute is valid only if used alone.
FILE_ATTRIBUTE_OFFLINE      The data of the file is not immediately available. Indicates that the file data has been physically moved to offline storage.
FILE_ATTRIBUTE_READONLY      The file or directory is read-only. Applications can read the file but cannot write to it or delete it. In the case of a directory, applications cannot delete it.
FILE_ATTRIBUTE_SYSTEM      The file or directory is part of, or is used exclusively by, the operating system.
FILE_ATTRIBUTE_TEMPORARY      The file is being used for temporary storage. File systems attempt to keep all of the data in memory for quicker access rather than flushing the data back to mass storage. A temporary file should be deleted by the application as soon as it is no longer needed.

You can retrieve the file Date using "GetFileTime", the size with "GetFileSize", an you can retrieve a lot of information on a file using "GetFileInformationByHandle" which needs a "BY_HANDLE_FILE_INFORMATION" structure... Although these functions need a handle to an open file, which you can obtain with "CreateFile"...

All the declarations needed can be found in your API text viewer.
If you have any questions, just tell me.
0
 

Expert Comment

by:jmnolan
ID: 1454406
APIs would work, but you really want to do something more like this.

To copy a file, use the FileCopy command like this

FileCopy SourcePath, DestinationPath

Here is how you would go through a directory and get the file attrbiutes you want:

Dim Attr1 As String
Dim Attr2 As Long
Dim MyPath, MyName

MyPath = "c:\*.*"  ' Set the path.
MyName = Dir(MyPath, vbDirectory) ' Retrieve the first entry.

Do While MyName <> ""   ' Start the loop.
    'Ignore the current directory and the encompassing directory.
    If MyName <> "." And MyName <> ".." Then
        Attr1 = FileDateTime("c:\" & MyName)
        Attr2 = FileLen("c:\" & MyName)
        MsgBox "c:\" & MyName & vbCrLf & Attr1 & vbCrLf & Attr2
    End If
    MyName = Dir    ' Get next entry.
Loop


0
 

Author Comment

by:carla1
ID: 1454407
Your answer was helpful, but jmnolan's answer was what I was looking for.

jmnolan: Your code worked great.  If you want the points, please post your answer for me to accept.
Thanks
0
 

Accepted Solution

by:
jmnolan earned 200 total points
ID: 1454408
Please refer to my comment.. =)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month16 days, 1 hour left to enroll

850 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