-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile_dir_lib.awk
More file actions
executable file
·63 lines (57 loc) · 1.34 KB
/
file_dir_lib.awk
File metadata and controls
executable file
·63 lines (57 loc) · 1.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
#
# NAME
# file_dir_lib.awk
#
# DESCRIPTION
# A library of functions related to files and directories
#
# NOTES
# Use it appending "-f file_dir_lib.awk" to the awk call
#
# AUTHOR
# Jesus Cuenca
#
# VERSION
# 1.0
#
# HISTORY
# 1.0 - Initial release
# Return a file name valid in DOS (but with no 8.3 length check)
# Characters in SKIP_CHARS are not validated
function DOS_compliant_filename (FILE_NAME,SKIP_CHARS){
gsub("=.3","",FILE_NAME)
gsub("Ì\\201","",FILE_NAME)
gsub("=","",FILE_NAME)
gsub("Ì.","",FILE_NAME)
# Replace sequences of dots and trailing dots
gsub("\\.*\\.",".",FILE_NAME)
gsub("\\.\\.",".",FILE_NAME)
end_index=length(FILE_NAME)
end_char=substr(FILE_NAME,end_index,end_index)
if (end_char == ".")
FILE_NAME=substr(FILE_NAME,1,end_index -1)
gsub("[#()~,:&?;|]","",FILE_NAME)
gsub("\\[","",FILE_NAME)
gsub("\\]","",FILE_NAME)
if (index(SKIP_CHARS,"/") == 0)
gsub("/","",FILE_NAME)
gsub("\\","",FILE_NAME)
if(index(SKIP_CHARS, " ") == 0)
gsub(" ","",FILE_NAME)
gsub("\\*","",FILE_NAME)
return FILE_NAME
}
# Return the file name from a MAC OS full path
# In Mac, the directory separator is ':'
function extract_filename_mac(MAC_PATH){
n=split(MAC_PATH, path,":")
return path[n]
}
function check_file_exists(FILE_NAME){
if ((getline kk < FILE_NAME) > 0){
# Found it
close(FILE_NAME)
return 1
}
return 0
}