amakrkr Posted December 1, 2011 Share Posted December 1, 2011 (edited) Hello all. I require some help because i am kinda stuck with a script which is supposed to do the following: I will provide path as parameter 1 and file name without an extension as parameter 2 via cmd. Then i need to check if 2 same named files exist on the provided path (disregarding extension) and also last modified time (day,mont,year:hour,minute) of the both files - times must match down to a minute. If 2 of those files are found then .txt file will be formed and something will be written to it. I hope i made it clear what am i trying to do here. Below is a sample script ... so far i manage to find 2 files (names matching) but still lacking time (last modified) match ... i just dont know how to do that. Any help would be apreciated! Thank you! #include <Array.au3> #include <File.au3> $File = "c:temptest.dat" $file_open = FileOpen($File, 2) $Path = $CmdLine[1] $filename = $CmdLine[2] $List = _FileListToArray($Path,"*",1) $list_cut= _FileListToArray($Path,"*",1) $counter = 0 for $i = 1 to ubound($list) -1 $list_cut[$i] = StringTrimRight($list[$i],4) if StringCompare($list_cut[$i],$filename) = 0 Then $counter = $counter +1 if $counter > 1 Then FileWriteLine($file_open,$filename & @CRLF) EndIf EndIf next FileClose($File_open) Edited December 4, 2011 by amakrkr Link to comment Share on other sites More sharing options...
amakrkr Posted December 4, 2011 Author Share Posted December 4, 2011 edited. Link to comment Share on other sites More sharing options...
Emiel Wieldraaijer Posted December 4, 2011 Share Posted December 4, 2011 This is not the answer but you asume your extension has including the dot a count of 4 .. how about docx ? Best regards, Emiel Best regards,Emiel Wieldraaijer Link to comment Share on other sites More sharing options...
Emiel Wieldraaijer Posted December 4, 2011 Share Posted December 4, 2011 Use FileGetTimeAnd maybe you should check this example Best regards,Emiel Wieldraaijer Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 4, 2011 Moderators Share Posted December 4, 2011 amakrkr,You need to use FileGetTime to check the timestamp of the files that match. This does what you want when I test it:expandcollapse popup#include <Array.au3> #include <File.au3> $File = @ScriptDir & "test.dat" $file_open = FileOpen($File, 2) ; Force another file to exist with the same timestamp FileOpen(@ScriptDir & "test.dbl", 2) $Path = $CmdLine[1] ; Force a trailing If StringRight($Path, 1) <> "" Then $Path &= "" $filename = $CmdLine[2] ; get list of files on path $List = _FileListToArray($Path, "*", 1) ; Create an array to hold any matching files Global $aMatches[$List[0] + 1][2] = [[0]] For $i = 1 To UBound($List) - 1 ; Delete the extension - using SRER means we can ignore the size of the extension $sListCut = StringRegExpReplace($List[$i], "(.*)..*", "$1") ; Does it match the required string If StringCompare($sListCut, $filename) = 0 Then ; Increase the count $aMatches[0][0] += 1 ; Store the file name $aMatches[$aMatches[0][0]][0] = $List[$i] ; Store the modified time - remove the SS at then end of the string $aMatches[$aMatches[0][0]][1] = StringTrimRight(FileGetTime($Path & $List[$i], 0, 1), 2) EndIf Next ; Just for display _ArrayDisplay($aMatches, "Final") If $aMatches[0][0] > 1 Then ; Look at each turn For $i = 1 To $aMatches[0][0] - 1 ; And try to match with all subsequent For $j = 2 To $aMatches[0][0] ; Do the timestamps match If $aMatches[$i][1] = $aMatches[$j][1] Then ; Write to the file FileWrite($file_open, $Path & $aMatches[$i][0] & @CRLF) EndIf Next Next EndIf ; Empty the array $aMatches = 0 FileClose($file_open)Please ask if you have any questions. M23 amakrkr 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
kylomas Posted December 4, 2011 Share Posted December 4, 2011 Melba, amakrkr, This may or may not be pertinent but, file names may be more than 2 nodes long, e.g. "my.new.exe", "my.new.exe.txt", etc. I do NOT know what the actual limits are. kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 4, 2011 Moderators Share Posted December 4, 2011 kylomas, Which is why I used an SRER to get the name. If you try it you will see that it removes only the final extension, no matter how long it is: $sFileName_1 = "mynew.doc" $sFileName_2 = "my.new.docx" $sStripped_1 = StringRegExpReplace($sFileName_1, "(.*)..*", "$1") $sStripped_2 = StringRegExpReplace($sFileName_2, "(.*)..*", "$1") MsgBox(0, "Stripped", $sStripped_1 & @CRLF & $sStripped_2) Convinced now? M23 amakrkr 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
kylomas Posted December 4, 2011 Share Posted December 4, 2011 M23, Yes, I see, sorry !!! Too early here for SRE work (SRE = headache). kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 4, 2011 Moderators Share Posted December 4, 2011 kylomas,SRE = headacheVery true! M23 amakrkr 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
kylomas Posted December 4, 2011 Share Posted December 4, 2011 amakrkr, Apologies for thread hijack but we may both learn something here. @M23, Do I interpret the SRER as: (.*) - capture all groups . - followed by a period .* - followed by anything else then replace with all captured groups???? I do NOT get how this winnows the last node from the filename. kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 4, 2011 Moderators Share Posted December 4, 2011 (edited) kylomas,Pretty close. Remember that SREs are "greedy" by default and so always look for the largest possible match (unless you tell them otherwise of course) So the SRER translates as:(.*) - Capture as many characters as you can until... . - you find a . (because of the "greediness" this will always be the final one)... .* - which is followed by any number of characters (so we can ignore the length of the extension) $1 - Replace the whole lot with the captured groupAll clear? I always recommend this site as a good place to learn about SREs - and GEOSoft's PCRE Toolkit (look in his sig) as a good way to play with them to see exactly what they do. M23Edit: I see jchd looking in - stand by for incoming! Edited December 4, 2011 by Melba23 amakrkr 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
kylomas Posted December 4, 2011 Share Posted December 4, 2011 M23, Thanks, kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
jchd Posted December 4, 2011 Share Posted December 4, 2011 Nothing to add to what our Flying DutchMan GentleMan said. You know he's an SRE guru by now. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 4, 2011 Moderators Share Posted December 4, 2011 jchd, Thanks for the compliments, but I would only class myself as an apprentice guru at best. amakrkr, Are you still out there? M23 amakrkr 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
amakrkr Posted December 5, 2011 Author Share Posted December 5, 2011 Woah .. so many replays, sorry for a late replay. First of all thank you all for so much of a positive feedback.Let me start about extensions ... Function StringRegExpReplace how did i miss that? Altho i know what kind of a file extensions there will be (max 4 chars long including the dot).I now realize i have much to learn about coding ... i was off by a mile with my way of thinking. Using arrays like that ... I have learned quite a bit today so thanks again Melba23 for taking the time and solving this problem for me. My DBA will be really happy that she wont need to copy / paste files by hand anymore. PS FileGetTime - i knew about the function ... but i didnt have any idea how to implement it in my script ... you should see the scripts i tried to make before i came here posting this. Thanks again! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now