;; FileNanny
;; "Go to your room !"
;; by ak
#SingleInstance ignore
iniFile = %A_ScriptDir%\FileNanny.ini
if 0 = 0
{
gosub CreateGUI
gosub checkboxes
}
else
{
Iniread shiftKey, %iniFile%, options, shiftKey
GetKeyState kstate, Shift
if (shiftKey = 1 and kstate = "D")
editFolder = 1
if (shiftKey = 0 and kstate = "U")
editfolder = 1
Loop, %0%
{
param := %A_Index%
SplitPath param, fileName, dirName, extension, fileNameNoExt
rawName = %fileNameNoExt%
gosub convert
if editFolder = 1
{
InputBox InputRawName, FileNanny, Name of the folder to create, , 320, 120, , , , , %rawName%
rawName = %InputRawName%
if ErrorLevel
ExitApp
}
FileMove %param%, %param%.FileNanny
dirToCreate = %dirName%\%rawName%
FileCreateDir %dirToCreate%
FileMove %param%.FileNanny, %param%
fileNewName = %rawName%.%extension%
FileMove %param%, %dirToCreate%\%fileNewName%
}
ExitApp
}
return
CreateGUI:
gui destroy
RegRead, regTest, HKEY_CLASSES_ROOT, *\shell\FileNanny
if strlen(regTest) = 0
{
button1Text = Add context menu item
button1Action = addCMI
}
else
{
button1Text = Remove context menu item
button1Action = remCMI
}
sendToFolder = %UserProfile%\SendTo
ifnotExist %sendToFolder%\filenanny.lnk
{
button2text = Add 'Send to' shortcut
button2action = addST
}
else
{
button2text = Remove 'Send to' shortcut
button2action = remST
}
Gui, Add, Button, x126 y195 w70 h30 gQuit, Quit
Gui, Add, Tab, x3 y5 w315 h230 vSelectedTab, Configuration|Options
Gui, Font, s9 w600
Gui tab, Configuration
Gui font, norm
Gui, Add, Button, x90 y65 w140 h30 g%button1Action% vCMIb, %button1Text%
Gui, Add, Button, x90 y125 w140 h30 g%button2Action% vSTb, %button2Text%
Gui tab, Options
if strlen(regTest) = 0
{
regTest = n/a
disabledOrNot = disabled
}
Gui, Add, text, x26 y59 w190 h20 vCurrentCMI, Current : %regTest%
Gui, Add, Button, x226 y55 w70 h20 %disabledOrNot% gchangeCMI vCMIc, Change
Gui, Add, GroupBox, x16 y35 w290 h50 , Context menu text
Gui, Add, CheckBox, x16 y95 w300 h30 vshiftKey gini, Holding the Shift key is required to modify `nfolder name before its creation
Gui, Add, GroupBox, x16 y135 w290 h50 , Convert these to spaces
Gui, Add, CheckBox, x30 y150 w50 h30 vconvDot gini, .
Gui, Add, CheckBox, x80 y150 w50 h30 vconvMinus gini, -
Gui, Add, CheckBox, x130 y150 w50 h30 vconvUnderscore gini, _
Gui, Add, CheckBox, x180 y150 w50 h30 vconvPercent gini, `%20
Gui, Show, h240 w320, FileNanny
return
ini:
Gui submit, NoHide
Iniwrite %shiftKey%, %iniFile%, options, shiftkey
Iniwrite %convDot%, %iniFile%, convert, dots
Iniwrite %convMinus%, %iniFile%, convert, minus
Iniwrite %convUnderscore%, %iniFile%, convert, underscore
Iniwrite %convPercent%, %iniFile%, convert, percent
return
checkBoxes:
Iniread shiftKey, %iniFile%, options, shiftKey
Iniread convDot, %iniFile%, convert, dots
Iniread convMinus, %iniFile%, convert, minus
Iniread convUnderscore, %iniFile%, convert, underscore
Iniread convPercent, %iniFile%, convert, percent
Guicontrol ,,shiftKey, %shiftKey%
Guicontrol ,,convDot, %convDot%
Guicontrol ,,convMinus, %convMinus%
Guicontrol ,,convUnderscore, %convUnderscore%
Guicontrol ,,convPercent, %convPercent%
return
convert:
Iniread convDot, %iniFile%, convert, dots
Iniread convMinus, %iniFile%, convert, minus
Iniread convUnderscore, %iniFile%, convert, underscore
Iniread convPercent, %iniFile%, convert, percent
if convDot = 1
StringReplace rawName, rawName, ., %A_SPACE%, A
if convMinus = 1
StringReplace rawName, rawName, -, %A_SPACE%, A
if convUnderscore = 1
StringReplace rawName, rawName, _, %A_SPACE%, A
if convPercent = 1
StringReplace rawName, rawName, `%20, %A_SPACE%, A
return
ChangeCMI:
RegRead, regTest, HKEY_CLASSES_ROOT, *\shell\FileNanny
transform,eperluette,chr,0x26
Inputbox newCMI, Enter new context menu text, Please choose the text that will appear in the context menu., , , , , , , , %regTest%
If ErrorLevel
{
return
}
else
{
RegWrite, REG_SZ, HKEY_CLASSES_ROOT, *\shell\FileNanny, , %newCMI%
Guicontrol,, currentCMI, Current : %newCMI%
}
return
AddCMI:
RegWrite, REG_SZ, HKEY_CLASSES_ROOT, *\shell\FileNanny, , FileNann&y !
RegWrite, REG_SZ, HKEY_CLASSES_ROOT, *\shell\FileNanny\command, , "%A_ScriptFullPath%" "`%L"
Guicontrol,, CMIb, Remove context menu item
Guicontrol +gremCMI, CMIb
Guicontrol,, currentCMI, Current : FileNann&y !
Guicontrol enable, CMIc
return
RemCMI:
RegDelete HKEY_CLASSES_ROOT, *\shell\FileNanny
Guicontrol,, CMIb, Add context menu item
Guicontrol +gaddCMI, CMIb
Guicontrol,, currentCMI, Current : n/a
Guicontrol disable, CMIc
return
addST:
FileCreateShortcut, %A_ScriptFullPath%, %sendToFolder%\filenanny.lnk
Guicontrol,, STb, Remove 'Send to' shortcut
Guicontrol +gremST, STb
return
remST:
FileDelete, %sendToFolder%\filenanny.lnk
Guicontrol,, STb, Add 'Send to' shortcut
Guicontrol +gaddST, STb
return
Quit:
GuiClose:
GuiEscape:
ExitApp
return