Make a backup file: Difference between revisions

Added FreeBASIC
m (syntax highlighting fixup automation)
(Added FreeBASIC)
 
(2 intermediate revisions by 2 users not shown)
Line 194:
 
hd(System.argv) |> RC.backup_file</syntaxhighlight>
 
=={{header|Forth}}==
<syntaxhighlight lang="forth">
: backup ( addr u -- )
2dup pad place s" .bak" pad +place
2dup pad count rename-file throw
w/o create-file throw
s" This is a test string." 2 pick write-file throw
close-file throw ;
 
s" testfile" backup</syntaxhighlight>
 
=={{header|FreeBASIC}}==
<syntaxhighlight lang="vbnet">Sub saveWithBackup(filePath As String, lines() As String)
Dim As String origPath = filePath
If Len(Dir(origPath)) > 0 Then
Dim As String backupPath = origPath & ".backup"
Name(origPath, backupPath) 'Renames a file on disk
End If
Open origPath For Output As #1
For i As Integer = 1 To Ubound(lines)
Print #1, lines(i)
Next i
Close #1
End Sub
 
Dim lines(1 To 3) As String => {"fourth", "fifth", "sixth"}
saveWithBackup("original.txt", lines())
 
Dim As String linea
' check it worked
Print "Current contents of original.txt:"
Open "original.txt" For Input As #1
While Not Eof(1)
Line Input #1, linea
Print linea
Wend
Close #1
 
Print !"\nContents of original.txt.backup:"
Open "original.txt.backup" For Input As #1
While Not Eof(1)
Line Input #1, linea
Print linea
Wend
Close #1
 
Sleep</syntaxhighlight>
{{out}}
Contents of 'original.txt' ''before'' the program is run and of 'original.txt.backup' ''after'' it is run:
<pre>
first
second
third
</pre>
 
Contents of 'original.txt' ''after'' the program is run:
<pre>
fourth
fifth
sixth
</pre>
 
=={{header|Go}}==
Line 861 ⟶ 923:
=={{header|Wren}}==
{{libheader|Wren-ioutil}}
<syntaxhighlight lang="ecmascriptwren">import "./ioutil" for File, FileUtil
 
var saveWithBackup = Fn.new { |filePath, lines|
2,122

edits