get individual file names from the command-line file path
| 1134 | |
| 1135 | // get individual file names from the command-line file path |
| 1136 | void ASConsole::getFilePaths(string &filePath) |
| 1137 | { |
| 1138 | fileName.clear(); |
| 1139 | targetDirectory = string(); |
| 1140 | targetFilename = string(); |
| 1141 | |
| 1142 | // separate directory and file name |
| 1143 | size_t separator = filePath.find_last_of(g_fileSeparator); |
| 1144 | if (separator == string::npos) |
| 1145 | { |
| 1146 | // if no directory is present, use the currently active directory |
| 1147 | targetDirectory = getCurrentDirectory(filePath); |
| 1148 | targetFilename = filePath; |
| 1149 | mainDirectoryLength = targetDirectory.length() + 1; // +1 includes trailing separator |
| 1150 | } |
| 1151 | else |
| 1152 | { |
| 1153 | targetDirectory = filePath.substr(0, separator); |
| 1154 | targetFilename = filePath.substr(separator + 1); |
| 1155 | mainDirectoryLength = targetDirectory.length() + 1; // +1 includes trailing separator |
| 1156 | } |
| 1157 | |
| 1158 | if (targetFilename.length() == 0) |
| 1159 | { |
| 1160 | fprintf(stderr, _("Missing filename in %s\n"), filePath.c_str()); |
| 1161 | error(); |
| 1162 | } |
| 1163 | |
| 1164 | // check filename for wildcards |
| 1165 | hasWildcard = false; |
| 1166 | if (targetFilename.find_first_of( "*?") != string::npos) |
| 1167 | hasWildcard = true; |
| 1168 | |
| 1169 | // clear exclude hits vector |
| 1170 | for (size_t ix = 0; ix < excludeHitsVector.size(); ix++) |
| 1171 | excludeHitsVector[ix] = false; |
| 1172 | |
| 1173 | // If the filename is not quoted on Linux, bash will replace the |
| 1174 | // wildcard instead of passing it to the program. |
| 1175 | if (isRecursive && !hasWildcard) |
| 1176 | { |
| 1177 | fprintf(stderr, "%s\n", _("Recursive option with no wildcard")); |
| 1178 | #ifndef _WIN32 |
| 1179 | fprintf(stderr, "%s\n", _("Did you intend quote the filename")); |
| 1180 | #endif |
| 1181 | error(); |
| 1182 | } |
| 1183 | |
| 1184 | // display directory name for wildcard processing |
| 1185 | if (hasWildcard) |
| 1186 | { |
| 1187 | printSeparatingLine(); |
| 1188 | printMsg(_("Directory %s\n"), targetDirectory + g_fileSeparator + targetFilename); |
| 1189 | } |
| 1190 | |
| 1191 | // create a vector of paths and file names to process |
| 1192 | if (hasWildcard || isRecursive) |
| 1193 | getFileNames(targetDirectory, targetFilename); |