Sign in to follow this  
Followers 0
Christen

DirMove returns 0

4 posts in this topic

Hi there all you clever guys

I'm new to AutoIt, so I've lende from example scripts to accomplish below script, titled "Swap ScreenSavers".

Its purpose is to set a change source folder for my Windows 7 screensaver photo slide show with each call, intentionally at boot time.

I have several slide shows, each located in a subfolder to a folder named ..MyScreensaver/0, and the active one, pointed to by my Windows 7 screensaver settings beeing the folder ..MyScreensaver/1. The change of source folder is swapping folders between the two subfolders ..1 and ..0. It's really quite simple (compared to changing the registry settings at boot time ;)

The script depends on DirMove, but I can't figure out, why it doesn't work - any suggestions and help would be appreciated!

Below is my script, as you see, I've tried with and without trailing "\":

Thanks in advance

Christen

;Swap Screensavers
;Folder pointed to by Windows 7 screen saver photo slide show is ..\MyScreensaver\1
;E.g. with active ScreensaverFolder in folder 1 being folder b:
;..\MyScreensaver\
;0\
;1\
;..\MyScreensaver\0\
;a\
;c\
;..\MyScreensaver\1\
;b\
;first call moves folder b to folder 0 and folder c to folder 1.
;Second call moves folder c to folder 0 and folder a to folder 1
;Third moves folder a to folder 0 and folder b to folder 1. Etc.
#include "C:\Program Files (x86)\AutoIt3\Include\Array.au3"
Local $MyScreensaverFolder = "D:\Users\Christen\Pictures\MyScreensaver\1"
Local $ScreensaverFolder = "D:\Users\Christen\Pictures\MyScreensaver\0"
Local $SearchMyScreensaver = FileFindFirstFile($MyScreensaverFolder & "\*.*")
If $SearchMyScreensaver = -1 Then
    Exit
EndIf
Local $MyScreensaver = FileFindNextFile($SearchMyScreensaver)
MsgBox(0, "$MyScreensaver:", $MyScreensaver)
Local $FolderArray[1] = [$MyScreensaver]
Local $SearchScreensavers = FileFindFirstFile($ScreensaverFolder & "\*.*")
If $SearchScreensavers = -1 Then
    Exit
EndIf
Local $Screensavers = FileFindNextFile($SearchScreensavers)
_ArrayAdd($FolderArray, $Screensavers)
While 1
If $Screensavers = -1 Then
  ExitLoop
EndIf
$Screensavers = FileFindNextFile($SearchScreensavers)
If @error Then ExitLoop
_ArrayAdd($FolderArray, $Screensavers)
WEnd
_ArraySort($FolderArray)
_ArrayDisplay($FolderArray)
Local $MoveOldScreensaver = DirMove( $MyScreensaverFolder & "\" & $MyScreensaver, $ScreensaverFolder )
MsgBox(0, "DirMove Old:", "From:" & @CRLF & $MyScreensaverFolder & "\" & $MyScreensaver & @CRLF & "To:" & @CRLF & $ScreensaverFolder & @CRLF & "Result: " &  $MoveOldScreensaver)
;Local $MoveOldScreensaver = DirMove( $MyScreensaverFolder & "\" & $MyScreensaver & "\", $ScreensaverFolder & "\" )
;MsgBox(0, "DirMove Old:", "From:" & @CRLF & $MyScreensaverFolder & "\" & $MyScreensaver & "\" & @CRLF & "To:" & @CRLF & $ScreensaverFolder & "\" & @CRLF & "Result: " &  $MoveOldScreensaver)
; Next folder in Array with wrap-around
Local $NewScreensaverIndex = _ArraySearch($FolderArray, $MyScreensaver) + 1
If $NewScreensaverIndex =  UBound( $FolderArray ) Then
$NewScreensaverIndex = 0
EndIf
Local $NewScreensaver = $FolderArray[$NewScreensaverIndex]
Local $MoveNewScreensaver = DirMove( $ScreensaverFolder & "\" & $NewScreensaver, $MyScreensaverFolder )
MsgBox(0, "DirMove New:", "From:" & @CRLF & $ScreensaverFolder & "\" & $NewScreensaver & @CRLF & "To:" & @CRLF & $MyScreensaverFolder & @CRLF & "Result: " &  $MoveNewScreensaver)
;Local $MoveNewScreensaver = DirMove( $ScreensaverFolder & "\" & $NewScreensaver & "\", $MyScreensaverFolder & "\" )
;MsgBox(0, "DirMove New:", "From:" & @CRLF & $ScreensaverFolder & "\" & $NewScreensaver & "\" & @CRLF & "To:" & @CRLF & $MyScreensaverFolder & "\" & @CRLF & "Result: " &  $MoveNewScreensaver)

Share this post


Link to post
Share on other sites



Looking at your code and I believe JScript has it as well. You're pulling the filename with "FileFindNextFile()". DirMove() is for entire folders with no trailing backslash.


Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Share this post


Link to post
Share on other sites

I found another approach using runDLL and the actual window Screen Saver Settings. The titles of the windows used are in Danish, and must be altered for use in other languages. It looks funny, but it works. Is there any way to access the settings invisibly, it would be nice!

Thanks for your help anyway, JScript and Blue Drache

;Set Screensaver Source Folder
;Folder pointed to by Windows 7 screen saver photo slide show
#include "C:\Program Files (x86)\AutoIt3\Include\Array.au3"
#include "C:\Program Files (x86)\AutoIt3\Include\File.au3"
Local $MyScreensaversFolder = "D:UsersChristenPicturesMyScreensavers"
Local $MyScreensaversList = _FileListToArray($MyScreensaversFolder,"*",2)
If @error = 1 Then
MsgBox(0, "", "No Folders Found.")
Exit
EndIf
;_ArrayDisplay($MyScreensaversList, "MyScreensavers")
Local $pMyScreensaver = IniRead( $MyScreensaversFolder & "MyScreensaver.ini", "MyScreensaver", "pMyScreensaver", 0 ) + 1
If $pMyScreensaver = $MyScreensaversList[0] Then
$pMyScreensaver = 1
EndIf
If IniWrite( $MyScreensaversFolder & "MyScreensaver.ini", "MyScreensaver", "pMyScreensaver", $pMyScreensaver ) = 0 Then
MsgBox(0, "MyScreensaver.ini", "Error writing ini-file.")
Exit
EndIf
Local $MyScreensaver = $MyScreensaversFolder & "" & $MyScreensaversList[$pMyScreensaver]
;MsgBox(0, "MyScreensaver", "MyScreensaver=" & $MyScreensaver)
Run( "C:\Windows\System32\rundll32.exe shell32.dll,Control_RunDLL desk.cpl,,1" )
WinWaitActive("Indstillinger for pauseskærm")
;Send("{ALTDOWN}i{ALTUP}")
Send("!i")
WinWaitActive("Indstillinger for pauseskærmen Billeder")
;Send("{ALTDOWN}e{ALTUP}")
Send("!e")
WinWaitActive("Angiv en mappe")
;Send("{ALTDOWN}m{ALTUP}")
Send("!m")
WinWaitActive("Angiv en mappe")
Send("+{END}{DEL}")
Send( $MyScreensaver, 1 )
Send("{ENTER}")
WinWaitActive("Indstillinger for pauseskærmen Billeder")
Send("!g")
WinWaitActive("Indstillinger for pauseskærm")
Send("{ENTER}")
Exit

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0