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