Solved

Moving Files in VB 5.0

Posted on 1998-06-09
4
146 Views
Last Modified: 2010-05-03
Greetings,
A process I have uses files that reside on another server. My problem is that server more that occasionally crashes. What is the best way to move the files I need to another server using VB if possible? FileCopy will only copy info into another file.

Also, how can I access the modified date of the file. I only want to move files that were created/modified yesterday.

Would a .bat file be easier? This should be fairly easy, I just can seem to find any documentation.

Thanks,
Brad
0
Comment
Question by:bhummel
  • 2
  • 2
4 Comments
 
LVL 6

Accepted Solution

by:
clifABB earned 100 total points
Comment Utility
To move a file in vb, use a combination of Copy and Kill.  This is actually better because you can test for a complete (and accurate) copy before deleting the original file.

As far as access a file's date, use FileDateTime():
MyStamp = FileDateTime("TESTFILE")      
0
 

Expert Comment

by:MikeABB
Comment Utility
You can move the files to the other machine using the name function.

Name <oldfilename> as <newfilename>

as for checking the modified date, you could use the GetFileTime API:

Declare Function GetFileTime& Lib "kernel32" (ByVal hFile as Long, lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, lpLastWriteTime as FILETIME)

Type FILETIME
        dwLowDateTime As Long
        dwHighDateTime As Long
End Type

lpLastWriteTime will give you your last modification time.

You can get more information on this function in the MSDN Online documentation.  After you get the time of the file, you can use the DateDiff function to determine if the file needs to be copied.
0
 

Expert Comment

by:MikeABB
Comment Utility
bhummel,
    Sorry about that, It was just pointed out to me, by clifABB, that the Name statement only works when files are on the same directory.  You should probably use the FileDateTime function too.  I was unaware that it existed.  Sorry again!

MikeABB
0
 
LVL 6

Expert Comment

by:clifABB
Comment Utility
Not the same directory, but both source and destination must be on the same drive.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now