|
-
April 18th, 2002, 07:32 AM
#1
copy last modified file from directory Visual Basic
okay at work we get credit card transaction from a unix mailbox that need moved to a PC network drive then transferred via FTP to our mainframe drives so that the cobol programs can manipulate the data.
the problem is that the file is not named with any pattern at all (like the date it's recieved) so I never know what the name of the file will be. Only that it will have a .dat extension. What I am trying to do is look into the folder where the files are and copy the last modified .dat file to the network drive and name it greentre.dat. can anyone guide me as to how to start.
-
April 18th, 2002, 08:04 AM
#2
Registered User
What type of system is the .dat file stored on and what computer will you run this program from?
-
April 18th, 2002, 09:36 AM
#3
the .dat file is downloaded to our computer room PC running win98 in a local folder. (we pull it in using procomm plus) I'll just be executing the command from the local pc to send the last created file from the local folder to the network drive as a different name.
now I have to use dos command
cd\
cd progra~1\procom~1\downloads
copy *032.dat i:\xmit\greentre.dat (I use last 3 digits of whatever the file is named that day)
If they would just send them to us with some logical pattern to the batch name It would be easy. I've gotten our other credit card report file figured out but it uses the date of the file in it's name.
-
April 18th, 2002, 10:09 AM
#4
Registered User
Try this:
[code]
Dim fso, Folder, FileList, File, LastMod As Variant
Dim dHigh As Long
Set fso = CreateObject("Scripting.FileSystemObject")
Set Folder = fso.GetFolder("C:\MyDirectory")
Set FileList = Folder.Files
dHigh = 0
For Each File In FileList
If File.DateLastModified > dHigh Then
dHigh = File.DateLastModified
LastMod = File.Name
End If
Next File
' Now you have the file name in LastMod.
' FTP that filename
</pre><hr></blockquote>
This should get you the last modified file in the directory you specify for MyDirectory.
-
April 18th, 2002, 10:16 AM
#5
Registered User
Do you already have a method to FTP the file once you've found it?
-
April 18th, 2002, 11:01 AM
#6
[quote]Originally posted by Deity:
<strong>Do you already have a method to FTP the file once you've found it?</strong><hr></blockquote>
diety,
thank you again. I do have a FTP script on the mainframe side which will pull the file from the PC network drive.
one more quick questions. Can I specify only .dat files in the code you sent me, and where specifically(just in case there is a text file or something in there too)
-
April 18th, 2002, 11:24 AM
#7
Registered User
Just modify the For..Each Loop to check for .dat files like this:
[code] For Each File In FileList
If File.DateLastModified > dHigh And Right(File.Name, 3) = "dat" Then
dHigh = File.DateLastModified
LastMod = File.Name
End If
Next File
</pre><hr></blockquote>
This will only check the dat files.
-
April 18th, 2002, 11:42 AM
#8
I wish you could teach my class! I've learned more with you helping me twice than the countless hours I've spent in that classroom
thanks so much
-
April 18th, 2002, 11:47 AM
#9
Registered User
Do you have a copy of the MSDN library? If you don't you can always find it at Microsoft's site. The MSDN is a great source.
-
April 18th, 2002, 11:55 AM
#10
Registered User
You also wanted to copy the file to a special folder with a specific name right? Here's how to do that:
[code]
fso.CopyFile "C:\MyDirectory\" & LastMod, "Path to new server/directory"
</pre><hr></blockquote>
Just tack that line after the loop. Some cleanup is needed also. Just add these lines after the copy.
[code]
Set FileList = Nothing
Set Folder = Nothing
Set fso = Nothing
</pre><hr></blockquote>
This makes the code a little cleaner.
-
April 18th, 2002, 11:57 AM
#11
Registered User
[quote]Originally posted by kato2274:
<strong>I wish you could teach my class! I've learned more with you helping me twice than the countless hours I've spent in that classroom
thanks so much</strong><hr></blockquote>
I'm glad to help. I was in your shoes once too. Luckily my programming instructor was wonderful. He was a good teacher and is now a good friend.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|
Bookmarks