-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfile_read.do
More file actions
152 lines (125 loc) · 3.34 KB
/
file_read.do
File metadata and controls
152 lines (125 loc) · 3.34 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
qui {
if 1 {
cls
clear all
set varabbrev on
capture log close
}
if 2 {
noi di as error "Current working directory: "
noi di in g "`c(pwd)'"
noi di " "
noi di "Please hit enter to proceed or enter the new path to change directory"
noi di "Enter exit to terminate", _request(path_c)
if ("${path_c}" != "") {
global path_c : di strtrim("${path_c}")
if (strupper("${path_c}") == "EXIT") {
noi di " "
noi di as error "Program Terminated"
noi di in g " "
exit
}
// detect entered pathway
if 1 {
capture cd "${path_c}"
while (_rc) {
noi di " "
noi di "You have entered an invalid path"
noi di "Please check and re-enter", _request(path_c)
if ("${path_c}" != "") {
global path_c : di strtrim("${path_c}")
if (strupper("${path_c}") == "EXIT") {
noi di " "
noi di as error "Program Terminated"
noi di in g " "
exit
}
capture cd "${path_c}"
}
else {
global root : di "`c(pwd)'"
capture cd "${root}"
}
}
global root : di "${path_c}"
}
}
else {
global root : di "`c(pwd)'"
}
if ("`c(os)'" == "Windows") {
global slash : di "\"
global del : di "del"
}
else {
global slash : di "/"
global del : di "rm"
}
cd "${root}"
if ("${path_c}" != "") {
noi di "Working directory succesffuly changed to: "
noi di "${root}"
noi di " "
}
}
if 3 {
// ask for the prefix
noi di " "
noi di "Please enter the name of this assignment on Courseplus drop box"
noi di "(e.g.: Assignment 1)", _request(ass_name)
global ass_name : di strtrim("${ass_name}")
if (strupper("${ass_name}") == "EXIT") {
noi di " "
noi di as error "Program Terminated"
noi di in g " "
exit
}
local prefix : di subinstr("${ass_name}", " ", "", .)
// ask for the extension
noi di " "
noi di "Please enter the extension for the submissions", _request(ext_name)
global ext_name : di strtrim("${ext_name}")
if (strupper("${ext_name}") == "EXIT") {
noi di " "
noi di as error "Program Terminated"
noi di in g " "
exit
}
local do_list_helper : dir . files "`prefix'*${ext_name}"
noi di " "
noi di as error "Do file submissions in folder detected: "
local count = 0
foreach i in `do_list_helper' {
noi di in g "`i'"
local count = `count' + 1
}
local sub_total = `count'
noi di "Total Counts: `count'"
noi di " "
}
if 4 {
// read in each file
// get the file handle name and read in to display each line
foreach i in `do_list_helper' {
noi di as error "Loading File Content For: ", _continue
noi di in g "`i'"
// get file handle name
local pos = strpos("`i'", "${ext_name}") - 1
local fh : di substr("`i'", 1, `pos')
// read in file
file open `fh' using "`i'", read write text
// read in lines
local line_count = 0
file read `fh' line
while (r(eof) == 0) {
local line_count = `line_count' + 1
noi di in g "Line `line_count':" _asis `" `macval(line)'"'
file read `fh' line
}
noi di as error "File End Reached"
noi di in g " "
file close `fh'
}
noi di "All files have been read in!"
}
}