1 // ----------------------------------------------------------------------------
3 // ----------------------------------------------------------------------------
7 // static char *VB_Name = "PathTools_Module";
10 // --- Option Compare Text
12 // ########### Quote & UnQuote ##################################################
14 void UnQuote(char *ST)
19 while (STRING_IS_LIKE(ST, "\"*"))
21 ST = Right(ST, L - 1);
25 while (STRING_IS_LIKE(ST, "*\""))
33 if (! STRING_IS_LIKE(ST, "\"*"))
36 if (! STRING_IS_LIKE(ST, "*\""))
40 char *UnQuoted(char *STRG)
49 while (STRING_IS_LIKE(ST, "\"*"))
51 ST = Right(ST, L - 1);
55 while (STRING_IS_LIKE(ST, "*\""))
65 char *Quoted(char *STRG)
72 if (! STRING_IS_LIKE(ST, "\"*"))
75 if (! STRING_IS_LIKE(ST, "*\""))
83 // ############ Path-/FileName-Extraction and concatanation ######################
85 char *StripDir(char *Path)
97 StripDir = StrReverse(Right(T, strlen(T) - i));
102 char *StripFileName(char *Path)
109 T = StrReverse(Path);
110 if (STRING_IS_LIKE(T, "/*"))
111 T = Right(T, strlen(T) - 1);
113 i = InStr(1, T, "/");
120 StripFileName = StrReverse(Left(T, i - 1));
122 return StripFileName;
125 char *StripExtension(char *Path)
127 char *StripExtension;
132 T = StrReverse(Path);
133 iSlash = InStr(1, T, "/");
134 i = InStr(1, T, ".");
135 if ((i < 2) || (iSlash < i))
138 StripExtension = StrReverse(Left(T, i - 1));
140 return StripExtension;
143 char *NewExtension(char *Path, char *NewExt)
147 // NewExtension("C:\MyPath\MyFile.Old","New") returns "C:\MyPath\MyFile.New"
148 // NewExtension("C:\MyPath.dir\MyFile","New") returns "C:\MyPath\MyFile.New"
150 long i, iSlash, ELen;
152 T = StrReverse(Path);
153 iSlash = InStr(1, T, "/");
154 i = InStr(1, T, ".");
155 if ((i < 1) || (iSlash < i))
160 NewExtension = CAT(Left(StrReverse(T), strlen(T) - i), ".", NewExt);
165 char *StripExtensionlessFileName(char *Path)
167 char *StripExtensionlessFileName;
172 T = StripFileName(Path);
173 T2 = StripExtension(Path);
174 StripExtensionlessFileName = Left(T, strlen(T) - strlen(T2) - (0 < strlen(T2) ? 1 : 0));
176 return StripExtensionlessFileName;
179 char *WithSlash(char *Path)
183 if (STRING_IS_LIKE(Path, "*/"))
189 WithSlash = CAT(Path, "/");
195 char *SlashLess(char *Path)
200 while (STRING_IS_LIKE(SlashLess, "*/"))
202 SlashLess = Left(Path, strlen(Path) - 1);
208 // ############ File-/Diresctory-Operations ######################################
210 boolean FileExists(char *Path)
214 if ((STRING_IS_LIKE(Dir(Path), "")) || (STRING_IS_LIKE(Path, "")))
222 void MayKill(char *Path)
225 // --- On Error GoTo MayKillEH
230 boolean IsDir(char *Path)
235 // --- On Error Resume Next
236 IsDir = (vbDirectory == (GetAttr(Path) & vbDirectory));
243 // ######### binary comparison of files ##########################################
245 boolean FilesEqual(char *Path1, char *Path2)
251 boolean b1Open, b2Open;
255 // Debug.Assert(FileExists(Path1));
256 // Debug.Assert(FileExists(Path2));
257 if (! (FileExists(Path1) && FileExists(Path2)))
260 nSize = FileLen(Path1);
261 if (nSize != FileLen(Path2))
264 bin1 = REDIM_1D(sizeof(byte), 0, nSize + 1 - 1);
265 bin2 = REDIM_1D(sizeof(byte), 0, nSize + 1 - 1);
269 // --- On Error GoTo FilesEqualEH
270 // FNum1 = FreeFile();
271 FNum1 = fopen(Path1, "rb");
273 FILE_GET(FNum1, -1, &bin1, sizeof(bin1));
276 // FNum2 = FreeFile();
277 FNum2 = fopen(Path2, "rb");
279 FILE_GET(FNum2, -1, &bin2, sizeof(bin2));
282 // --- On Error GoTo 0
284 for (i = 1; i <= nSize; i++)
286 if (bin1[i] != bin2[i]) // return false