Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need FileSystemObject help 1

Status
Not open for further replies.

YNOTU

Technical User
Jun 21, 2002
749
US
hello all,

Let me briefly explain how the script is suppossed to work and how it's not working.

1.
We receive daily files from our client for processing and all files received are named
filename04
and the script converts each file to
filename04_20041110.txt
which are then moved to a shared folder "2004 Files" folder on a server. All files with a "04" on the end are working fine as per the script


2.
The problem is with files with "05" on the end. As you can see by the script I modified it as far as I could but it's not working. (not good with this coding and here's where your help is necessary)


What is currently happening with "05" files is that the files are being moved to the root of the machine that receives And nothing is being appended to the end like 04 filesthem and not moved to the "2005 Folder" (as 04 file are) folder as per the script. And when the client sends multiple files the same day all "05" files are overwritten.


I really hope you guys can help on thisone but most importantly I hope you undertand my problem.


Thanks All



Code:
Option Explicit		'force explicit variable declaration
On Error Resume Next	'on error continue at next statement

' Initialize variables
Dim nowMonth, nowDay, nowYear
Dim now 
Dim ConfirmTxT, ConfRptTxt, PostCardTxT, OutFileTxT, Confirm04TXT, Confirm05TXT, Confirmcl04TXT, Confirmcl05TXT, Confirmny04TXT, Confirmny05TXT, ConfirmrptTXT

Dim FSO
now = date

nowMonth = Month(now)
nowDay = Day(now)
nowYear = Year(now)

ConfirmTxT = "i:\wcom\confirm_" & nowYear & nowMonth & nowDay & ".txt"
ConfRptTxT = "i:\wcom\confrpt_" & nowYear & nowMonth & nowDay & ".txt"
PostCardTxT = "i:\wcom\postcard_" & nowYear & nowMonth & nowDay & ".txt"
OutFileTxT = "i:\wcom\confirmcl_" &  nowYear & nowMonth & nowDay & ".txt"

'2004 Files
Confirm04TXT = "i:\wcom\2004 Files\confirm04_" & nowYear & nowMonth & nowDay & ".txt"
Confirmcl04TXT = "i:\wcom\2004 Files\confirmcl04_" & nowYear & nowMonth & nowDay & ".txt"
Confirmny04TXT = "i:\wcom\2004 Files\confirmny04_" & nowYear & nowMonth & nowDay & ".txt"
ConfirmrptTXT = "i:\wcom\2004 Files\confirmrpt_" & nowYear & nowMonth & nowDay & ".txt"


'2005 Files
Confirm05TXT = "i:\wcom\2005 Files\confirm05_" & nowYear & nowMonth & nowDay & ".txt"
Confirmcl05TXT = "i:\wcom\2005 Files\confirmcl05_" & nowYear & nowMonth & nowDay & ".txt"
Confirmny05TXT = "i:\wcom\2005 Files\confirmny05_" & nowYear & nowMonth & nowDay & ".txt"
ConfirmrptTXT = "i:\wcom\2005 Files\confirmrpt_" & nowYear & nowMonth & nowDay & ".txt"


Set FSO = CreateObject("Scripting.FileSystemObject")
FSO.CopyFile "g:\ftp\public\confirm.txt", ConfirmTxT
FSO.CopyFile "g:\ftp\public\confirmrpt.txt", ConfRptTxT
FSO.CopyFile "g:\ftp\public\postcard.txt", PostCardTxT
FSO.CopyFile "g:\ftp\public\confirmcl.txt", OutFileTxT

'2004 Files
FSO.CopyFile "g:\ftp\public\confirm04.txt", Confirm04TXT
FSO.CopyFile "g:\ftp\public\confirmcl04.txt", Confirmcl04TXT
FSO.CopyFile "g:\ftp\public\confirmny04.txt", Confirmny04TXT
FSO.CopyFile "g:\ftp\public\confirmrpt.txt", ConfirmrptTXT


'2005 Files
FSO.CopyFile "g:\ftp\public\confirm05.txt", Confirm05TXT
FSO.CopyFile "g:\ftp\public\confirmcl05.txt", Confirmcl05TXT
FSO.CopyFile "g:\ftp\public\confirmny05.txt", Confirmny05TXT
FSO.CopyFile "g:\ftp\public\confirmrpt.txt", ConfirmrptTXT


FSO.DeleteFile("g:\ftp\public\confirm.txt")
FSO.DeleteFile("g:\ftp\public\confrpt.txt")
FSO.DeleteFile("g:\ftp\public\postcard.txt")
FSO.DeleteFile("g:\ftp\public\confirmcl.txt")

'2004 Files
FSO.DeleteFile("g:\ftp\public\confirm04.txt")
FSO.DeleteFile("g:\ftp\public\confirmcl04.txt")
FSO.DeleteFile("g:\ftp\public\confirmny04.txt")
FSO.DeleteFile("g:\ftp\public\confirmrpt.txt")


'2005 Files
FSO.DeleteFile("g:\ftp\public\confirm05.txt")
FSO.DeleteFile("g:\ftp\public\confirmcl05.txt")
FSO.DeleteFile("g:\ftp\public\confirmny05.txt")
FSO.DeleteFile("g:\ftp\public\confirmrpt.txt")
 
Remove the On Error Resume Next statement to see what the specific error is.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Thanks for your response TomThumbKP, the script actually runs everyday at 2:00 am I don't run it manually and right now there are no files to test it....
 
Quick note: why not just create a quick file in xomething like notepad? Easy test file.

Now, on to the problem at hand.
My solution would be to firte get rid of all the hardcoding. If each file suffix for a year will always be the last two digits of the year, then you can easily write a script to cover yourself until dec 31 2099:
Code:
Option Explicit

'Declare some base path variables to make future changes easier
Dim BASE_FROM_PATH, BASE_TARGET_PATH
BASE_FROM_PATH = "g:\ftp\public\"
BASE_TARGET_PATH = "i:\wcom\"

Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")

'build the suffix once since it will always be the same
Dim file_suffix
file_suffix = "_" & Year(Now) & Month(Now) & Day(Now) & ".txt"

'Move the non-numbered files
MoveFile BASE_FROM_PATH & "confirm.txt", BASE_TARGET_PATH & "confirm" & file_suffix
MoveFile BASE_FROM_PATH & "confrpt.txt", BASE_TARGET_PATH & "confrpt" & file_suffix
MoveFile BASE_FROM_PATH & "postcard.txt", BASE_TARGET_PATH & "postcard" & file_suffix
MoveFile BASE_FROM_PATH & "confirmcl.txt", BASE_TARGET_PATH & "confirmcl" & file_suffix


'Move files for current year and next year
Dim filenames, afile
filenames = Array("confirm","conrimcl","confirmny","confirmrpt")
For Each afile In filenames
   MoveFile BASE_FROM_PATH & afile & Left(Year(now),2) & ".txt", BASE_TARGET_PATH & Year(Now) & " Files/" & 
afile & Left(Year(now,2)) & file_suffix
Next

'--- MoveFile function
'Function to manage all the copying and incremental naming for us
Function MoveFile(fromPath, toPath)
   Dim file_counter
   If Not fso.FileExists(toPath) Then
      fso.CopyFile fromPath, toPath
      fso.DeleteFile fromPath
   Else
      file_counter = 1
      Do Until Not fso.FileExists(Replace(toPath,".","(" & file_counter & ")."))
         file_counter = file_counter + 1
      Loop
      fso.CopyFile fromPath, Replace(toPath,".","(" & file_counter & ").")
      fso.DeleteFile fromPath
   End If
End Function


Anyways, that was writtebn on the fly and I probably would have condensed it a lot more if I was writing it for myself, hope it isn't to hard to follow,

-T

barcode_1.gif
 
thank you very much T I will give it a try and post back... I really appreciate it.

google.gif
juggle.gif

 
Thank you very much for your input Tarwn. I modified it enough with your suggestion to make it work.

google.gif
juggle.gif

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top