Solved

How do I read a file's Properties

Posted on 1999-01-06
5
202 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 50 total points
ID: 1454408
Please refer to my comment.. =)
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
to transfer string from C lanaguage to VBA 4 64
VBA: Select SQL query based on a config Sheet v2 11 44
Child Form in front 4 46
Advice in Xamarin 21 78
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

776 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