AutoHotkey Community

It is currently May 27th, 2012, 2:04 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: January 31st, 2010, 3:22 pm 
Otis needs your help..

I have folder with many subfolders, I need to have a script that will look in those subfolders and if there is only one file type then depending on the file type I want to delete or move the folder they are in.

Example,
Folders with rar files only will be moved to a location I set
Folders with zip files only will be deleted.

Can anyone help Otis? please.. no experience in scripting :(


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 31st, 2010, 4:19 pm 
Offline

Joined: August 3rd, 2009, 4:44 pm
Posts: 69
Location: UK
try this

Code:
SetWorkingDir %A_ScriptDir%

dir_to_check = %A_ScriptDir%

move_rars_to = ..\moved rars

Loop, %dir_to_check%\*, 2
   {
      hasother=no
      hasrar=no
      
      Loop, %A_LoopFileName%\*, 1, 1
      {
         if (A_LoopFileName!="Thumbs.db" && InStr(A_LoopFileAttrib, "D")=0)
         {
            SplitPath, A_LoopFileName,,, fileext
               
            if (fileext!="rar" && fileext!="zip")
            {
            hasother=yes
             break
            }
            
            if (fileext="rar")
            {
            filecreatedir, %move_rars_to%
            Filemove, %A_LoopFilefullPath%, %move_rars_to%
            if (errorlevel!=0)
            {            
            hasrar=yes
            }
            }
               
         }
      }

      if (hasother="no" && hasrar="no")
      {
         FileRemoveDir, %A_LoopFileName%, 1
      }
      
   }
 


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 31st, 2010, 6:03 pm 
Thanks horntail, but I have 2 problems..

It will move files, I want it to move the folder that contain those files.
Can you also make it rename if 2 folders to be moved will have the same name? Like in windows (1)(2)?

Im sorry for asking too much, but this will help Otis alot


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 31st, 2010, 8:59 pm 
Offline

Joined: August 3rd, 2009, 4:44 pm
Posts: 69
Location: UK
there you go

Code:
SetWorkingDir %A_ScriptDir%

dir_to_check = %A_ScriptDir%

move_to_dir = %A_desktop%\test

filecreatedir, %move_to_dir%

Loop, %dir_to_check%\*, 2
   {
      hasother=no
      hasrar=no
      
      Loop, %A_LoopFileName%\*, 1, 1
      {
         if (A_LoopFileName!="Thumbs.db" && InStr(A_LoopFileAttrib, "D")=0)
         {
            SplitPath, A_LoopFileName,,, fileext
               
            if (fileext!="rar" && fileext!="zip")
            {
               hasother=yes
                break
            }
            
            if (fileext="rar")
            {
               rardir:=A_LoopFileDir
               rardir2:=rardir
               hasrar=yes
            }
               
         }
      }

      if (hasother="no" && hasrar="no")
      {
         FileRemoveDir, %A_LoopFileName%, 1
      }
      
      if (hasrar="yes")
      {

         StringGetPos, sym_pos, rardir, \, R
      
         if (errorlevel=0)
         {
            rardir:=SubStr(rardir, sym_pos+2)
         }
         
         newdir=%move_to_dir%\%rardir%
         
         ifexist, %newdir%
         {
         
            loop
            {
               ifnotexist, %newdir% (%A_Index%)
               {   
                  newdir=%newdir% (%A_Index%)
                  break
               }
         
            }
         
         }
         
         Filemovedir, %rardir2%, %newdir%
         
      }
      
   }
 


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 31st, 2010, 9:46 pm 
Not working :?
Actually it doesn't do anything


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 31st, 2010, 10:33 pm 
Offline

Joined: August 3rd, 2009, 4:44 pm
Posts: 69
Location: UK
have you changed the directory its sending the files to? because the version i posted sends the files to a folder called test on your desktop


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 31st, 2010, 10:42 pm 
horntail wrote:
have you changed the directory its sending the files to? because the version i posted sends the files to a folder called test on your desktop


I did, no luck, can you please test it?

Sad Otis :?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 31st, 2010, 10:45 pm 
Offline

Joined: August 3rd, 2009, 4:44 pm
Posts: 69
Location: UK
what is it failing to do?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 31st, 2010, 11:26 pm 
horntail wrote:
what is it failing to do?


Its not moving or deleting, nothing


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: engunneer, nimda, sjc1000 and 15 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:
Powered by phpBB® Forum Software © phpBB Group