Can't think at the moment, another 2 mates died recently so I'm taking the easy way out.
Anyone know of a utility to move and sort based on modified date?
I have directory structures like this for my documents:
D:\Rabbity\Documents\Everyone\Purchases & Payments\Medical\
D:\Rabbity\Documents\Everyone\Purchases & Payments\Medical\Manuals
D:\Rabbity\Documents\Everyone\Purchases & Payments\Lighting
D:\Rabbity\Documents\Everyone\Purchases & Payments\Manuals
And wanted to sort all files found in the root 'Everyone' directory to something like this based on the date modified of the files found in those directories. Only the directories will have the date, the filenames will be untouched.
D:\Rabbity\Documents\Everyone\Purchases & Payments\Medical\02-06-2016
D:\Rabbity\Documents\Everyone\Purchases & Payments\Lighting\03-04-2010
Or Just
D:\Rabbity\Documents\Everyone\Purchases & Payments\01-03-2012
etc. etc.
Utility to move and sort based on modified date?
- Fangbeast
- PureBasic Protozoa

- Posts: 4795
- Joined: Fri Apr 25, 2003 3:08 pm
- Location: Not Sydney!!! (Bad water, no goats)
Utility to move and sort based on modified date?
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
Re: Utility to move and sort based on modified date?
would this work for you, the sorting part at least .
I wouldn't want to be responsible for borking your files, if I wrote code to move them.
Sorry about your mates leaving, just had one of my best leave too.
I wouldn't want to be responsible for borking your files, if I wrote code to move them.
Sorry about your mates leaving, just had one of my best leave too.
Code: Select all
EnableExplicit
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
#Cdir = "\"
CompilerElse
#Cdir = "/"
CompilerEndIf
Structure FileDate
Created.i
Modified.i
Accessed.i
EndStructure
Structure File
Name.s
Attributes.i
Date.FileDate
Size.q
EndStructure
Procedure GetFileList(StartDirectory.s,List Lfiles.file(),Pattern.s="*.*",Recursive=1)
Protected PatternCount,Depth,a,CurrentDirectoryID,Directory.s,TempDirectory.s
Protected FileAttributes.i,FileSize.i,FileDate.FileDate,FileName.s,FullFileName.s
Static NewList Lpattern.s()
Static PatternSet,FileCount
If Not PatternSet
Pattern = RemoveString(Pattern,"*.")
PatternCount = CountString(Pattern,"|") + 1
ClearList(lpattern())
For a = 1 To PatternCount
AddElement(Lpattern())
Lpattern() = UCase(StringField(Pattern,a,"|"))
Next
PatternSet=1
ElseIf depth = 0
PatternSet = 0
EndIf
CurrentDirectoryID = ExamineDirectory(#PB_Any, StartDirectory, "*.*")
If CurrentDirectoryID
While NextDirectoryEntry(CurrentDirectoryID)
If DirectoryEntryType(CurrentDirectoryID) = #PB_DirectoryEntry_File
Directory = StartDirectory
FileName = DirectoryEntryName(CurrentDirectoryID)
FileDate\Created = DirectoryEntryDate(CurrentDirectoryID,#PB_Date_Created)
FileDate\Modified = DirectoryEntryDate(CurrentDirectoryID,#PB_Date_Modified)
FileDate\Accessed = DirectoryEntryDate(CurrentDirectoryID,#PB_Date_Accessed)
FileAttributes = DirectoryEntryAttributes(CurrentDirectoryID)
FileSize = DirectoryEntrySize(CurrentDirectoryID)
ForEach Lpattern()
If lpattern() = "*" Or GetExtensionPart(UCase(FileName)) = lpattern()
FullFileName.s = StartDirectory + FileName
AddElement(LFiles())
Lfiles()\Name = FullFileName
Lfiles()\Date = FileDate
Lfiles()\Size = FileSize
Lfiles()\Attributes = FileAttributes
FileCount+1
EndIf
Next
Else
TempDirectory = DirectoryEntryName(CurrentDirectoryID)
If TempDirectory <> "." And TempDirectory <> ".."
If Recursive = 1
Depth + 1
GetFileList(StartDirectory + TempDirectory + #Cdir,LFiles(),Pattern,Recursive)
EndIf
EndIf
EndIf
Wend
FinishDirectory(CurrentDirectoryID)
EndIf
ProcedureReturn FileCount
EndProcedure
Procedure SortFileListByDate(List InputFiles.file(),List OutPutFiles.file(),Order=#PB_Sort_Ascending,DateOption=#PB_Date_Modified,StartDate=0,EndDate=$7FFFFFFF)
Select DateOption
Case #PB_Date_Modified
SortStructuredList(InputFiles(),Order,(OffsetOf(File\Date)+OffsetOf(FileDate\Modified)),#PB_Integer)
Case #PB_Date_Accessed
SortStructuredList(InputFiles(),Order,(OffsetOf(File\Date)+OffsetOf(FileDate\Accessed)),#PB_Integer)
Case #PB_Date_Created
SortStructuredList(InputFiles(),Order,(OffsetOf(File\Date)+OffsetOf(FileDate\Created)),#PB_Integer)
EndSelect
If StartDate
ForEach InputFiles()
Select DateOption
Case #PB_Date_Modified
If (InputFiles()\Date\Modified >= StartDate And InputFiles()\Date\Modified <= EndDate)
AddElement(OutPutFiles())
CopyStructure(@InputFiles(),@OutPutFiles(),File)
EndIf
Case #PB_Date_Accessed
If (InputFiles()\Date\Modified >= StartDate And InputFiles()\Date\Accessed <= EndDate)
AddElement(OutPutFiles())
CopyStructure(@InputFiles(),@OutPutFiles(),File)
EndIf
Case #PB_Date_Created
If (InputFiles()\Date\Modified >= StartDate And InputFiles()\Date\Created <= EndDate)
AddElement(OutPutFiles())
CopyStructure(@InputFiles(),@OutPutFiles(),File)
EndIf
EndSelect
Next
EndIf
ProcedureReturn ListSize(OutPutFiles())
EndProcedure
Procedure SortFileListBySize(List InputFiles.file(),List OutPutFiles.file(),Order=#PB_Sort_Ascending,MinimumSize=0,MaximumSize.q=$7FFFFFFFFFFFFFFF)
SortStructuredList(InputFiles(),Order,OffsetOf(File\Size),#PB_Integer)
If MinimumSize
ForEach InputFiles()
If (InputFiles()\Size >= MinimumSize And InputFiles()\Size <= MaximumSize)
AddElement(OutPutFiles())
CopyStructure(@InputFiles(),@OutPutFiles(),File)
EndIf
Next
EndIf
ProcedureReturn ListSize(OutPutFiles())
EndProcedure
Global NewList AllFiles.File()
Global NewList FilteredFiles.File()
Global NewList ReFilteredFiles.File()
Global StartDate = Date(2014,1,1,0,0,0)
Global EndDate = Date(2016,12,31,23,59,59)
Global path.s = #PB_Compiler_Home
If GetFileList(path,AllFiles(),"*.pb|*.pbi") ;get all pb files in the directory recursively
If SortFileListByDate(Allfiles(),FilteredFiles(),#PB_Sort_Ascending,#PB_Date_Modified,StartDate,EndDate) ;sort and filter by date between dates
ForEach FilteredFiles()
Debug FilteredFiles()\Name
Debug FormatDate("%dd/%mm/%yyyy",FilteredFiles()\Date\Modified)
Next
EndIf
Debug "++++++++++++++++++++++++++++++++++++++++++++++++++"
If SortFileListBySize(FilteredFiles(),ReFilteredFiles(),#PB_Sort_Descending,10000,100000) ;re-sort and filter by size between sizes
ForEach ReFilteredFiles()
Debug ReFilteredFiles()\Name
Debug Str(ReFilteredFiles()\Size / 1024) + " KB"
Next
EndIf
EndIf
Windows 11, Manjaro, Raspberry Pi OS


- Fangbeast
- PureBasic Protozoa

- Posts: 4795
- Joined: Fri Apr 25, 2003 3:08 pm
- Location: Not Sydney!!! (Bad water, no goats)
Re: Utility to move and sort based on modified date?
Sorting? Sorry, don't get it. Or maybe I do (Sigh)
The first friend died of liver cancer and he had told me he was doing okay. He'd been buried a month before anyone thought to tell me and I just found out a couple of days ago. The second friend I was told about on the same day as the first and he had hung himself a week after I had coffee with him and his @%$@^$%@^$ wife didn't ring me so that that I could pay my respects.
It's been a rough week for all of us.
**EDIT** Trying to find where the "//" came into it
D:\bangf\Documents\Everyone\\Medical & General Health\Weight Loss\Weight Watchers - Weekly Chart.Doc
**EDIT**
Sorted and works like a treat. Thanks Idle.
The first friend died of liver cancer and he had told me he was doing okay. He'd been buried a month before anyone thought to tell me and I just found out a couple of days ago. The second friend I was told about on the same day as the first and he had hung himself a week after I had coffee with him and his @%$@^$%@^$ wife didn't ring me so that that I could pay my respects.
It's been a rough week for all of us.
**EDIT** Trying to find where the "//" came into it
D:\bangf\Documents\Everyone\\Medical & General Health\Weight Loss\Weight Watchers - Weekly Chart.Doc
**EDIT**
Sorted and works like a treat. Thanks Idle.
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
Re: Utility to move and sort based on modified date?
Sorted is safer than borked.
Sorry about you loosing your mates without knowing.
Sorry about you loosing your mates without knowing.
Windows 11, Manjaro, Raspberry Pi OS


