Last active
November 20, 2023 20:52
-
-
Save MarkGoldberg/c053b1e2cfd1fa65ab547a530f76c1d3 to your computer and use it in GitHub Desktop.
Move Files into new folders based on Gaps in their Date/Time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
! NOTE this is NOT currently a functional program | |
! It's just a collection procedures to help with the task | |
MoveFilesByGap PROCEDURE(*File:Queue xQ, LONG xMinGapTicks) | |
ThisGroupStart LONG(1) | |
ThisGroupEnd LONG,AUTO | |
NextGroupStart LONG,AUTO | |
NewFolder CSTRING(FILE:MaxFileName) | |
CODE | |
SORT(xQ, xQ.Date, xQ.Time) | |
LOOP Until NextGroupStart = -1 | |
NextGroupStart = FindNextGap( xQ, xMinGapTicks, ThisGroupStart) | |
ThisGroupEnd = CHOOSE( NextGroupStart = -1, RECORDS(xQ), NextGroupStart - 1) | |
GET(xQ, ThisGroupStart) | |
NewFolder = '.\Group_' & FORMAT(xQ.Date, @D12) & '_' & FORMAT(xQ.Time, @T2) | |
MkDir( NewFolder) ! will need prototype for RTL command _mkdir | |
MoveFiles( xQ, ThisGroupStart, ThisGroupEnd, NewFolder) | |
ThisGroupStart = NextGroupStart | |
END | |
MoveFiles PROCEDURE (*File:Queue xQ , LONG xThisGroupStart, LONG xThisGroupEnd, STRING xNewFolder) | |
QPtr LONG,AUTO | |
CODE | |
LOOP QPtr = ThisGroupStart TO ThisGroupEnd | |
GET(xQ, QPtr) | |
MoveFile( xQ.Name, xNewFolder) | |
END | |
MoveFile PROCEDURE( STRING xFileName, STRING xNewFolder) | |
! carl barnes says: ! I would use the API MoveFile() or probably MoveFileEx() for more option flags | |
! carl barnes says: ! After seeing the mess created by "enhancing" Remove() in Clarion I tend to call API file files. | |
! carl barnes says: ! I would hope the API would be better at simply fixing up the NTFS Directory rather than a Copy and Remove | |
TempFile FILE,DRIVER('DOS') | |
RECORD | |
AByte BYTE | |
END | |
END | |
CODE | |
TempFile{PROP:Name} = xFileName | |
RENAME( TempFile, xNewFolder) | |
FindNextGap PROCEDURE(*File:Queue xQ, LONG xMinGapTicks, LONG xStartAtRow ),LONG | |
! Returns pointer in xQ of first entry that has a Date/Time > xMinGrapTicks from the previous entry | |
! will return -1 if there are no gaps | |
! we are ASSUMING that xQ is sorted by Date & Time | |
RetNextGap LONG(-1) | |
QPtr LONG,AUTO | |
PrevDate LONG,AUTO | |
PrevTime LONG,AUTO | |
CODE | |
IF xStartAtRow < 1 | |
GET(xQ, 1) | |
ELSE | |
GET(xQ, xStartAtRow) | |
END | |
PrevDate = xQ.Date | |
PrevTime = xQ.Time | |
LOOP QPtr = xStartAtRow + 1 TO RECORDS( xQ ) | |
GET(xQ, QPtr) | |
! ignore date for a bit... | |
IF xQ.Time > PrevTime + xMinGapTicks | |
RetNextGap = QPtr | |
BREAK | |
ELSE | |
PrevDate = xQ.Date | |
PrevTime = xQ.Time | |
END | |
END | |
RETURN RetNextGap |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment