Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help in doing a somewhat complex macro...
#1
hi i want to make a macro that does this:

i have a large number of subfolders under one main folder, i want to create a macro that goes trough every subfolder in this main folder looking for files with the extension xxxxxx.log every subfolder with this .log text file i want it to open the file and search for strings patterns like 'switch: 27388' or 'switch: 24/34 or 'dslam: 25-3-4' if it exist then i want it to create a folder with the string name it found but only the numbers part i.e '25-3-4' move the subfolder where the .log file is found to this new folder and then continue to search in the other subfolders...

ill try to sketch this.

<DIR1> no .log found

<DIR2> -> q2.log found -> open log search for string -> found 'switch: 27388' -> create folder in c:\<27388> -> move <DIR2> to c:\<27388> -> continue the search

<DIR3> no .log found

<DIR4> -> q1.log found -> open log search for string -> found 'switch: 24/34' -> create folder in c:\<2434> -> move <DIR2> to c:\<2434> -> continue the search

<DIR5> no .log found

<DIR6> no .log found

now i have two folders in c: called c:\2434\DIR2\ ...

is this possible in QM2? if so then i'm buying it! looking forward for your help.

gev.
#2
Not tested.

Code:
Copy      Help
;edit these strings to match your main folder
str mainfolder="c:\main folder\"
str filepattern="c:\main folder\*.log"

;find all log files and write full paths to array
ARRAY(str) a
Dir d
foreach(d filepattern FE_Dir 0xC)
,a[a.redim(-1)]=d.FileName(1)

;walk through the array
int i
for i 0 a.len
,str s ss sf
,sf.getfile(a[i]) ;;load file to variable
,;regular expressions
,str rx1="switch: (\d+)" ;;switch: and any number of digits
,str rx2="switch: (\d+/\d+)" ;;switch: and any number of digits with / somewhere in middle
,str rx3="dslam: (\d+-\d+-\d+)" ;;dslam: and any number of digits with two -
,;search and extract digits to s
,if(findrx(sf rx1 0 2 s 1)>=0)
,else if(findrx(sf rx2 0 2 s 1)>=0)
,else if(findrx(sf rx3 0 2 s 1)>=0)
,else continue ;;not found
,;found
,s.replacerx("[\/|<>?*:'']+") ;;remove bad characters
,s-mainfolder ;;make full path
,mkdir s ;;create new folder
,ss.getpath(a[i] "") ;;get folder containing the log file
,ren ss s ;;move the folder to the new folder
,
,
#3
it works!

the syntax of QM is easier then i thought it will be very usable in my work.

thank you for the quick reply and for a great tool!


Forum Jump:


Users browsing this thread: 1 Guest(s)