forked from telnet23/bas
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcp.bas
More file actions
89 lines (71 loc) · 2.69 KB
/
Copy pathcp.bas
File metadata and controls
89 lines (71 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
0 rem cp - copy files
rem usage: cp <source-file> <target-file>
local_n$ = th_sed$( argv$(0), "\.bas", "" )
local_v$ = "1.0.8"
local_a$ = "underwood"
if len( argv$(1) ) < 2 then : gosub 160 : end
if argv$(2) = "" then : gosub 160 : end
if not pos( dir$, argv$(1) ) then : ? "%file not found" : end
rem check for invalid file types
if pos( argv$(1), ".a2sav" ) then : ? "%invalid file type" : end
bad$ = ".exe" : gosub 500
bad$ = ".gam" : gosub 500
bad$ = ".a2" : gosub 500
bad$ = ".vt" : gosub 500
myf$ = mid$( mid$( dir$, instr( dir$, argv$(1) ) ), 2 )
myf$ = left$( myf$, instr( myf$, " " ) )
rem check if output file already exists
if pos(dir$, " " + argv$(2) + " ") then ? "%already exists, cannot overwrite" : end
? "Copying " chr$(34) myf$ chr$(34) " -> " chr$(34) argv$(2) chr$(34) " " ;
gosub 210
gosub 320
if fsize = 0 then ? "%file invalid, cannot copy 0 bytes" : end
gosub 370
? chr$(27) "[D " : ? "Done (" str$( nint( fsize / 1000 ) ) " KB copied)"
end
160 rem usage
? "%usage: " local_n$ " <source-file> <target-file>"
return
210 rem open input file
lnm = 1
open myf$, as #1
240 rem read line from input file
if typ(1) = 3 then goto 290
input# 1, A$
outFile$ = outFile$ + A$ + chr$(13) + chr$(10)
gosub 400
file$(lnm) = A$
lnm = lnm + 1
goto 240
290 rem close input file
close #1
flines = lnm
return
320 rem get file size
for o = 1 to flines
fsize = fsize + len( file$(o) )
next o
return
370 rem create new file
rem put one too many new lines in the file
nls$ = string$( flines + 1, chr$(13) + chr$(10) )
open argv$(2), as #1
?# 1, nl$
close #1 : rem this saves the file
rem overwrite newlines with file contents and then put pointer one line further
open argv$(2), as #1
?# 1, outFile$
?# 1, "",
close #1 : rem this re-saves the file and discards anything past the pointer
return
400 rem spinner
if iter mod(100) = 0 then ? chr$(27) "[D/" ;
if iter mod(200) = 0 then ? chr$(27) "[D-" ;
if iter mod(300) = 0 then ? chr$(27) "[D\" ;
if iter mod(400) = 0 then ? chr$(27) "[D|" ;
if iter mod(400) = 0 then iter = 0
iter = iter + 1
return
500 rem check for invalid file types
if right$( argv$(1), len( bad$ ) ) = bad$ then : ? "%invalid file type" : end
return