MCPcopy Index your code
hub / github.com/codeyourweb/irma / FormatPathFromComplexString

Function FormatPathFromComplexString

filehelper.go:119–155  ·  view source on GitHub ↗

FormatPathFromComplexString search for file/directory path and remove environments variables, quotes and extra parameters

(command string)

Source from the content-addressed store, hash-verified

117
118// FormatPathFromComplexString search for file/directory path and remove environments variables, quotes and extra parameters
119func FormatPathFromComplexString(command string) (paths []string) {
120 var buffer []string
121
122 // quoted path
123 if strings.Contains(command, `"`) || strings.Contains(command, `'`) {
124 re := regexp.MustCompile(`[\'\"](.+)[\'\"]`)
125 matches := re.FindStringSubmatch(command)
126 for i := range matches {
127 if i != 0 {
128 buffer = append(buffer, matches[i])
129 }
130 }
131 } else {
132 for _, i := range strings.Split(strings.Replace(command, ",", "", -1), " ") {
133 buffer = append(buffer, i)
134 }
135
136 }
137
138 for _, item := range buffer {
139 // environment variables
140 if strings.Contains(command, `%`) {
141 re := regexp.MustCompile(`%(\w+)%`)
142 res := re.FindStringSubmatch(item)
143 for i := range res {
144 item = strings.Replace(item, "%"+res[i]+"%", os.Getenv(res[i]), -1)
145 }
146 }
147
148 // check if file exists
149 if _, err := os.Stat(item); !os.IsNotExist(err) {
150 paths = append(paths, item)
151 }
152 }
153
154 return paths
155}
156
157// RetrivesFilesFromUserPath return a []string of available files from given path (includeFileExtensions is available only if listFiles is true)
158func RetrivesFilesFromUserPath(path string, listFiles bool, includeFileExtensions []string, recursive bool, verbose bool) ([]string, error) {

Callers 3

StartMenuAnalysisRoutineFunction · 0.85
RegistryAnalysisRoutineFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected