;CleanDesk.ahk
; Moves files and folders from the Desktop (or any other folder) to another folder
; Make rules for certain file types or file names to be ignored, replaced or renamed
; Save to file and use AutoHotkey from www.autohotkey.com to run it
;Skrommel @ 2006
;Settings
timer=2000 ;How often to check for new files in ms
status=0 ;0=Hide 1=Show Traytip of files being moved
1source=%A_Desktop% ;Use variables like %A_Desktop%, %A_ScriptDir%, %A_MyDocuments%, %A_StartMenu%
1target=%A_Desktop%\Desktop ; %A_AppData%, %A_ProgramFiles%, %A_WinDir%
1files=* ;Files to move, supports wildcards * and ?
1ignore=jpg,jpeg ;Filenames and extensions to ignore, separated by comma. No wildcards!
1replace=2 ;0=No 1=Yes 2=Ask 3=Rename
2source=%A_DesktopCommon% ;%A_DesktopCommon%, %A_StartMenuCommon%, %A_ProgramsCommon%
2target=%A_DesktopCommon%\Desktop ;
2files=* ;Files to move, supports wildcards * and ?
2ignore= ;Filenames and extensions to ignore
2replace=2 ;0=No 1=Yes 2=Ask 3=Rename
3source=%A_Desktop%
3target=%A_Desktop%\Desktop
3files=*.jp*g ;Only jpg and jpeg images
3ignore=
3replace=3 ;Rename if same name
;Program
#Persistent
#SingleInstance,Force
SetTimer,TIMER,%timer%
Return
TIMER:
SetTimer,TIMER,%timer%,Off
Loop,9
{
counter:=A_Index
source:=%counter%source
target:=%counter%target
files:=%counter%files
ignore:=%counter%ignore
replace:=%counter%replace
If source=
Continue
Gosub,CLEAN
}
SetTimer,TIMER,%timer%,On
Return
CLEAN:
Loop,%source%\%files%,1,0
{
ext:=A_LoopFileExt
name:=A_LoopFileName
longpath:=A_LoopFileLongPath
If ext In %ignore%
Continue
If name In %ignore%
Continue
If longpath In %ignore%
Continue
If status=1
TrayTip,%applicationname%,%longpath%
FileGetAttrib,attrib,%longpath%
IfInString,attrib,D
Gosub,FOLDER
Else
Gosub,FILE
}
Return
FOLDER:
FileCreateDir,%target%
If replace=0
{
FileMoveDir,%longpath%,%target%,R
If ErrorLevel=1
FileMoveDir,%longpath%,%target%,0
}
Else
If replace=1
{
FileMoveDir,%longpath%,%target%,R
If ErrorLevel=1
FileMoveDir,%longpath%,%target%,2
}
Else
If replace=2
{
IfExist,%target%\%name%
{
MsgBox,3,%applicationname%,Replace folder %target%\%name% ?
IfMsgBox,Yes
FileMoveDir,%longpath%,%target%,1
IfMsgBox,No
{
ignore=%ignore%,%longpath%
%counter%ignore=%ignore%
}
IfMsgBox,Cancel
ExitApp
}
Else
{
FileMoveDir,%longpath%,%target%,R ;Doesn't work !?
If ErrorLevel=1
FileMoveDir,%longpath%,%target%,1 ;Should really be 0 !?
}
}
Else
If replace=3
{
IfExist,%target%\%name%
{
FileMoveDir,%longpath%,%target%\%name%-%A_Now%.%ext%,R
If ErrorLevel=1
FileMoveDir,%longpath%,%target%\%name%-%A_Now%.%ext%,0
}
Else
{
FileMoveDir,%longpath%,%target%,R
If ErrorLevel=1
FileMoveDir,%longpath%,%target%,0
}
}
Return
FILE:
If replace In 0,1
FileMove,%longpath%,%target%,%replace%
Else
If replace=2
{
IfExist,%target%\%name%
{
MsgBox,3,%applicationname%,Replace file %target%\%name% ?
IfMsgBox,Yes
FileMove,%longpath%,%target%,1
IfMsgBox,No
{
ignore=%ignore%,%longpath%
%counter%ignore=%ignore%
}
IfMsgBox,Cancel
ExitApp
}
Else
FileMove,%longpath%,%target%,0
}
Else
If replace=3
{
IfExist,%target%\%name%
FileMove,%longpath%,%target%\%name%-%A_Now%.%ext%,0
Else
FileMove,%longpath%,%target%,0
}
Return