Save Windows Spotlight photos
Posted: Thu May 25, 2017 8:26 am
Windows 10 includes the Spotlight feature, which shows very beautiful photos from various locations in the world. The following short code copies all Windows Spotlight photos to a directory of your choice.
On my PC, I have compiled the code to an EXE program, and have put a link to it into Windows' Autostart folder. So on every startup, all new Spotlight photos are automatically saved to the destination directory. Enjoy your growing collection of those pleasing photos!
On my PC, I have compiled the code to an EXE program, and have put a link to it into Windows' Autostart folder. So on every startup, all new Spotlight photos are automatically saved to the destination directory. Enjoy your growing collection of those pleasing photos!

Code: Select all
; >> Executable format: Console
; tested with PB 5.44 LTS on Windows 10
EnableExplicit
Procedure.i IsJpegFile (file$)
; out: 1 = yes
; 0 = no
; -1 = unknown
Protected ifn.i, firstWord.u, ret.i
ifn = ReadFile(#PB_Any, file$)
If ifn = 0
ProcedureReturn -1 ; error
EndIf
firstWord = ReadWord(ifn)
If firstWord = $D8FF
ret = 1
Else
ret = 0
EndIf
CloseFile(ifn)
ProcedureReturn ret
EndProcedure
Procedure.i CopySpotlightPhotos (targetDir$)
; in : full name of the target directory
; out: 1 on success,
; 0 on error
Protected sourceDir$, sourceFile$, targetFile$, console.i, dir.i, count.i=0
If FileSize(targetDir$) <> -2 ; if target directory does not exist
ProcedureReturn 0 ; error
EndIf
sourceDir$ = GetHomeDirectory() + "AppData\Local\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalState\Assets"
console = OpenConsole()
dir = ExamineDirectory(#PB_Any, sourceDir$, "*.*")
If dir
While NextDirectoryEntry(dir)
If DirectoryEntryType(dir) = #PB_DirectoryEntry_File And
DirectoryEntrySize(dir) > 50000 ; Small files in that directory are not Spotlight photos.
sourceFile$ = sourceDir$ + "\" + DirectoryEntryName(dir)
If IsJpegFile(sourceFile$) = 1
targetFile$ = targetDir$ + "\" + DirectoryEntryName(dir) + ".jpg"
CopyFile(sourceFile$, targetFile$)
count + 1
If console
PrintN(targetFile$)
EndIf
EndIf
EndIf
Wend
FinishDirectory(dir)
EndIf
If console
PrintN("")
Print("Copied " + count + " files.")
Delay(2000)
CloseConsole()
EndIf
ProcedureReturn 1 ; success
EndProcedure
Define targetDir$ = GetHomeDirectory() + "Pictures\WindowsSpotlight"
If CopySpotlightPhotos(targetDir$) = 0
MessageRequester("Error", "Target directory '" + targetDir$ + "' not found.")
EndIf