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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

what's wrong with this script - trying to call a function 1

Status
Not open for further replies.

gtubb

Programmer
Jan 15, 2004
24
GB
Hi folks

The following script copies a file to a backup folder, and dates it by renaming it 'backup30012004' - the digits are today's date, minus the '/'s

It works until I try to call the function checkdup(filename) which is supposed to add an extra digit on the end of the name of the backed up file if there is already one with todays date on.

Can anyone tell me what I need to change to stop the script hanging?

Many thanks

Gerard
 
Err, you need to add 5 on line 6... :)

Can we see that section of code, might be easier than guessing ;)

01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
The never-completed website:
 
Sorry - it's been a long day of progamming :)


Set fso = CreateObject("Scripting.FileSystemObject")
sDate = Date
sDate = Replace(sDate, "/", "")
sourceFile = "c:\upload\test.html"
destFile = "c:\upload\backup\backup_"& sDate &".html"
Call CheckDup(FileName)
fso.CopyFile sourceFile,destFile,true

'Verifies that the backup was created
If fso.FileExists("c:\upload\backup\backup_"& sDate &".html") Then
response.write "file backed up."
Else
response.write "file backup failed"
End If
Set fso = Nothing

Function CheckDup(FileName)
i = 1
NameCh = FileName
Do
DupFile = fso.FileExists("c:\upload\backup\backup_"& sDate &".html")
If DupFile = True Then
i = i+1
NameCh = FileName & "-" & i
End If
Loop While DupFile = True
End function
%>
 
Your CheckDup() function is not changing the variable destFile..

I usually do it this way:


<%

Function GenerateFilename()
dim destFile, fso, i
Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;)
i = 0
Do
destFile = &quot;c:\upload\backup\backup_&quot; &_
replace(date, &quot;/&quot;, &quot;&quot;) &_
right(&quot;000&quot; & i, 3) & &quot;.html&quot; ' leading zero's
if not fso.FileExists( destFile ) then
exit do
End If
i = i + 1
Loop
set fso = nothing
GenerateFilename = destFile
End function



response.Write GenerateFilename()
' use it now in your fso.CopyFile

%>

hth,
Foxbox
ttmug.gif
 
Forgive my ignorance, but how does the script pick up the source file?
 
Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;)
sourceFile = &quot;c:\upload\test.html&quot;
Call CheckDup(FileName)
fso.CopyFile sourceFile,GenerateFilename(),true

'Verifies that the backup was created
If fso.FileExists(&quot;c:\upload\backup\backup_&quot;& sDate &&quot;.html&quot;) Then
response.write &quot;file backed up.&quot;
Else
response.write &quot;file backup failed&quot;
End If
Set fso = Nothing


hth,
Foxbox
ttmug.gif
 
too fast!
remove the Call CheckDup(FileName) too!


hth,
Foxbox
ttmug.gif
 
I've adapted the function to write the correct version of the backup (if the response.write comes after the fso.copyfile it writes the current file plus one increment)

I can't work out what variable to put in the brackets after if fso.FileExists to make the script report &quot;file backed up.&quot; or &quot;file backup failed&quot; - but then maybe I should quit while I'm ahead.

Thanks for being such a great help

Gerard
 
<%
Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;)
sourceFile = &quot;c:\upload\test.html&quot;
cTargetFile = GenerateFilename()
fso.CopyFile sourceFile, cTargetFile,true

'Verifies that the backup was created
If fso.FileExists( cTargetFile ) Then
response.write &quot;file backed up.&quot;
Else
response.write &quot;file backup failed&quot;
End If
Set fso = Nothing
%>








hth,
Foxbox
ttmug.gif
 
Foxbox, you're a star.

The full script for anyone who wants to create a backup (in this case of a database)to a separate folder, date it and number each version sequentially is as follows:

<%
dim backedfile
Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;)
'change the following to location of file to be backed up
sourceFile = &quot;c:\upload\test.mdb&quot;
cTargetFile = GenerateFilename()
fso.CopyFile sourceFile,cTargetFile,true
'change the path beloww as above
backedfile = replace(cTargetFile, &quot;c:\upload\backup\&quot;, &quot;&quot;)
'Verifies that the backup was created
If fso.FileExists( cTargetFile ) Then
response.write &quot;The file <b>&quot; & backedfile & &quot; </b>was created successfully.&quot;
Else
response.write &quot;file backup failed&quot;
End If
Set fso = Nothing

'removes the /'s from the date and numbers backups if more than one is made in a day
Function GenerateFilename()
dim destFile, fso, i, backedfile
Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;)
i = 0
Do
destFile = &quot;c:\upload\backup\backup_&quot; &_
replace(date, &quot;/&quot;, &quot;&quot;) &_
right(&quot;_0&quot; & i, 3) & &quot;.mdb&quot; ' leading zero's
if not fso.FileExists( destFile ) then
exit do
End If
i = i + 1
Loop
set fso = nothing
GenerateFilename = destFile
End function
%>
 
Hello.

I am totally new in Internet. I used Dreamweaver to make pages and upload on my web site.

But i have another need related with Html and IE win98.
I seek an agreement Translation in exchange of Support for TUNING A FREE WYSIWYG EDITOR using A textarea :
- 1) to Write/SAVE Both in a RAMDRIVE and SAVE on a Physical DRICE C:/ else. I need to load a TEXT file with HTML code.
- 2) when i fill the base in the textarea of the wysiwyg editor, i would like to open another wysiwyg editor in which will be displayed the tanslation of what i type on the former editor.

The translation utility is no priority, but the mechanism of writing the same text on two or more editor is A MUST.

Any help accepted.
I can translate from Italian English Spanish TO FRENCH !

etlec better write back to
le_premier_bourguignon@yahoo.fr

Thank you, in advance.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top