AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Folders with one file type

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Otis
Guest





PostPosted: Sun Jan 31, 2010 2:22 pm    Post subject: Folders with one file type Reply with quote

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 Sad
Back to top
horntail



Joined: 03 Aug 2009
Posts: 69
Location: UK

PostPosted: Sun Jan 31, 2010 3:19 pm    Post subject: Reply with quote

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
      }
      
   }
 
Back to top
View user's profile Send private message
Otis
Guest





PostPosted: Sun Jan 31, 2010 5:03 pm    Post subject: Reply with quote

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
Back to top
horntail



Joined: 03 Aug 2009
Posts: 69
Location: UK

PostPosted: Sun Jan 31, 2010 7:59 pm    Post subject: Reply with quote

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%
         
      }
      
   }
 
Back to top
View user's profile Send private message
Otis
Guest





PostPosted: Sun Jan 31, 2010 8:46 pm    Post subject: Reply with quote

Not working Confused
Actually it doesn't do anything
Back to top
horntail



Joined: 03 Aug 2009
Posts: 69
Location: UK

PostPosted: Sun Jan 31, 2010 9:33 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
Otis
Guest





PostPosted: Sun Jan 31, 2010 9:42 pm    Post subject: Reply with quote

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 Confused
Back to top
horntail



Joined: 03 Aug 2009
Posts: 69
Location: UK

PostPosted: Sun Jan 31, 2010 9:45 pm    Post subject: Reply with quote

what is it failing to do?
Back to top
View user's profile Send private message
Otis
Guest





PostPosted: Sun Jan 31, 2010 10:26 pm    Post subject: Reply with quote

horntail wrote:
what is it failing to do?


Its not moving or deleting, nothing
Back to top
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group