AutoHotkey Community

It is currently May 27th, 2012, 3:50 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: August 6th, 2010, 10:04 am 
Offline

Joined: July 20th, 2009, 11:27 pm
Posts: 40
Not sure how to phrase this problem.

I'm making a desktop/folder cleanup script. It works fine when the GUI runs once, but when it runs again it says I can't use the same variables twice. Not sure why I'm getting this problem.

use windows + space to simulate it being called again

Code:
;
; AutoHotkey Version: 1.x
; Language:       English
; Platform:       Win9x/NT
; Author:         A.N.Other <myemail@nowhere.com>
;
; Script Function:
;   Template script (you can customize this template by editing "ShellNew\Template.ahk" in your Windows folder)
;

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
EnvGet, USERP, USERPROFILE
#SingleInstance,Force
bagin:
Gui, Add, Radio,vrdel checked gwhatdo x36 y167 w100 h30,&Delete them
Gui, Add, Radio,vrmove gwhatdo x36 y197 w100 h30,&Move them
Gui, Add, Edit,gextns vext x36 y47 w220 h20 -VScroll +Lowercase -VScroll,torrent
gui,submit,nohide
Gui, Add, Edit,vMPath disabled x36 y267 w220 h20 -VScroll, %USERP%\Desktop\%ext%
Gui, Add, Text, x36 y27 w220 h20 , What extension would you like to deal with?
Gui, Add, Text, x36 y137 w220 h20 , What would you like to do with the files?
Gui, Add, Text, x36 y87 w220 h20 , What folder do you want to work in?
Gui, Add, Edit, vwp x36 y107 w220 h20 , %USERP%\Desktop\
Gui, Add, Text, x36 y237 w220 h20 , Where do you want to move them?
Gui, Add, Button, x156 y307 w100 h30 ,Cancel
Gui, Add, Button,default x36 y307 w100 h30 ,OK
GuiControl, Focus,ext
; Generated using SmartGUI Creator 4.0
Gui, Show, x252 y98 h367 w296, New GUI Window
Return


extns:
   gui,submit,nohide
Guicontrol,,MPath,%USERP%\Desktop\%ext%\;auto edits the folder as you type the extension
return


whatdo:
GuiControlGet, rmove
if rmove  ; This box is checked.
{
   GuiControl, Enable, MPath;enables the move path if you select to move the files
   gui,submit,nohide
}
else
   GuiControl, Disable, MPath;disables the move path if you select to delete the files
return


;Made to detect the extension on drop
GuiDropFiles:
   Splitpath,A_GuiEvent,,,ext2
   Guicontrol,,ext,%ext2%
   Guicontrol,,MPath,%USERP%\Desktop\%ext2%
   return
   

ButtonOK:
   gui,submit
   stringright,slash,wp,1
   if (slash="\") ;checks if the path has a ending slash and adds it if its missing
   {
   }
   else wp=%wp%\
   ;small part to move all pics into one folder
If (ext="pics")
{
   loop,4
   {
      if (A_Index=1)
      {
         ext=jpg
      }
      if (A_Index=2)
      {
         ext=gif
      }
      if (A_Index=3)
      {
         ext=png
      }
      if (A_Index=4)
      {
         ext=bmp
      }
   gosub,actualloop
   }
   return
}
actualloop:
   loop,%wp%*.%ext%
   {
      if (rdel=1)
      {
         FileDelete,%A_LoopFileFullPath%;deletes the files in a loop
      }
      else if (rmove=1)
      {
         IfNotExist,%Mpath%
         {
            FileCreateDir,%Mpath%;moves the files in a loop
         }
         FileMove,%A_LoopFileFullPath%,%Mpath%
      }
   }
return

;********************************************************
;on kill
;********************************************************


ButtonCancel:
GuiClose:
   GuiEscape:
      Gui, destroy
return


#space::
   gosub,bagin


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 6th, 2010, 10:42 am 
Offline
User avatar

Joined: September 5th, 2009, 2:06 pm
Posts: 1713
Location: Somewhere near you
Code:
;
; AutoHotkey Version: 1.x
; Language:       English
; Platform:       Win9x/NT
; Author:         A.N.Other <myemail@nowhere.com>
;
; Script Function:
;   Template script (you can customize this template by editing "ShellNew\Template.ahk" in your Windows folder)
;

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
EnvGet, USERP, USERPROFILE
#SingleInstance,Force
bagin:
gui, destroy
Gui, Add, Radio,vrdel checked gwhatdo x36 y167 w100 h30,&Delete them
Gui, Add, Radio,vrmove gwhatdo x36 y197 w100 h30,&Move them
Gui, Add, Edit,gextns vext x36 y47 w220 h20 -VScroll +Lowercase -VScroll,torrent
gui,submit,nohide
Gui, Add, Edit,vMPath disabled x36 y267 w220 h20 -VScroll, %USERP%\Desktop\%ext%
Gui, Add, Text, x36 y27 w220 h20 , What extension would you like to deal with?
Gui, Add, Text, x36 y137 w220 h20 , What would you like to do with the files?
Gui, Add, Text, x36 y87 w220 h20 , What folder do you want to work in?
Gui, Add, Edit, vwp x36 y107 w220 h20 , %USERP%\Desktop\
Gui, Add, Text, x36 y237 w220 h20 , Where do you want to move them?
Gui, Add, Button, x156 y307 w100 h30 ,Cancel
Gui, Add, Button,default x36 y307 w100 h30 ,OK
GuiControl, Focus,ext
; Generated using SmartGUI Creator 4.0
Gui, Show, x252 y98 h367 w296, New GUI Window
Return


extns:
   gui,submit,nohide
Guicontrol,,MPath,%USERP%\Desktop\%ext%\;auto edits the folder as you type the extension
return


whatdo:
GuiControlGet, rmove
if rmove  ; This box is checked.
{
   GuiControl, Enable, MPath;enables the move path if you select to move the files
   gui,submit,nohide
}
else
   GuiControl, Disable, MPath;disables the move path if you select to delete the files
return


;Made to detect the extension on drop
GuiDropFiles:
   Splitpath,A_GuiEvent,,,ext2
   Guicontrol,,ext,%ext2%
   Guicontrol,,MPath,%USERP%\Desktop\%ext2%
   return
   

ButtonOK:
   gui,submit
   stringright,slash,wp,1
   if (slash="\") ;checks if the path has a ending slash and adds it if its missing
   {
   }
   else wp=%wp%\
   ;small part to move all pics into one folder
If (ext="pics")
{
   loop,4
   {
      if (A_Index=1)
      {
         ext=jpg
      }
      if (A_Index=2)
      {
         ext=gif
      }
      if (A_Index=3)
      {
         ext=png
      }
      if (A_Index=4)
      {
         ext=bmp
      }
   gosub,actualloop
   }
   return
}
actualloop:
   loop,%wp%*.%ext%
   {
      if (rdel=1)
      {
         FileDelete,%A_LoopFileFullPath%;deletes the files in a loop
      }
      else if (rmove=1)
      {
         IfNotExist,%Mpath%
         {
            FileCreateDir,%Mpath%;moves the files in a loop
         }
         FileMove,%A_LoopFileFullPath%,%Mpath%
      }
   }
return

;********************************************************
;on kill
;********************************************************


ButtonCancel:
GuiClose:
   GuiEscape:
      Gui, destroy
return


#space::
   gosub,bagin

Done.. :lol:

_________________
Image
The quick onyx goblin jumps over the lazy dwarf


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 6th, 2010, 10:44 am 
Offline

Joined: July 20th, 2009, 11:27 pm
Posts: 40
lol 1 line fix....
Thanks didn't think to do that
Thanks for the help


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 6th, 2010, 10:49 am 
Offline
User avatar

Joined: September 5th, 2009, 2:06 pm
Posts: 1713
Location: Somewhere near you
No problem =)
Be sure to visit the forum again..

_________________
Image
The quick onyx goblin jumps over the lazy dwarf


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 6th, 2010, 11:19 am 
dwjp90 wrote:
lol 1 line fix....

...you both really made me do it huh?

Code:
diff -u dwjp90.txt tomoe_uehara.txt
--- dwjp90.txt  Fri Aug 06 05:53:21 2010
+++ tomoe_uehara.txt    Fri Aug 06 05:53:43 2010
@@ -14,6 +14,7 @@
 EnvGet, USERP, USERPROFILE
 #SingleInstance,Force
 bagin:
+gui, destroy
 Gui, Add, Radio,vrdel checked gwhatdo x36 y167 w100 h30,&Delete them
 Gui, Add, Radio,vrmove gwhatdo x36 y197 w100 h30,&Move them
 Gui, Add, Edit,gextns vext x36 y47 w220 h20 -VScroll +Lowercase -VScroll,torrent

...tomoe: why not post what's wrong, instead of the entire script again with one hidden line fixed?

Also, this is the easiest, but not the best, way to fix this problem (well, unless the intent is clearing the GUI {but people use Gui, Destroy out of convenience to fix other problems}).


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 6th, 2010, 2:16 pm 
Offline
User avatar

Joined: September 5th, 2009, 2:06 pm
Posts: 1713
Location: Somewhere near you
Guest wrote:
...tomoe: why not post what's wrong, instead of the entire script again with one hidden line fixed?

It's just like the InStr command, try to find the needle in the haystack =)

_________________
Image
The quick onyx goblin jumps over the lazy dwarf


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], bobbysoon and 21 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
cron
Powered by phpBB® Forum Software © phpBB Group