 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Otis Guest
|
Posted: Sun Jan 31, 2010 2:22 pm Post subject: Folders with one file type |
|
|
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  |
|
| Back to top |
|
 |
horntail
Joined: 03 Aug 2009 Posts: 69 Location: UK
|
Posted: Sun Jan 31, 2010 3:19 pm Post subject: |
|
|
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 |
|
 |
Otis Guest
|
Posted: Sun Jan 31, 2010 5:03 pm Post subject: |
|
|
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
|
Posted: Sun Jan 31, 2010 7:59 pm Post subject: |
|
|
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 |
|
 |
Otis Guest
|
Posted: Sun Jan 31, 2010 8:46 pm Post subject: |
|
|
Not working
Actually it doesn't do anything |
|
| Back to top |
|
 |
horntail
Joined: 03 Aug 2009 Posts: 69 Location: UK
|
Posted: Sun Jan 31, 2010 9:33 pm Post subject: |
|
|
| 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 |
|
 |
Otis Guest
|
Posted: Sun Jan 31, 2010 9:42 pm Post subject: |
|
|
| 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  |
|
| Back to top |
|
 |
horntail
Joined: 03 Aug 2009 Posts: 69 Location: UK
|
Posted: Sun Jan 31, 2010 9:45 pm Post subject: |
|
|
| what is it failing to do? |
|
| Back to top |
|
 |
Otis Guest
|
Posted: Sun Jan 31, 2010 10:26 pm Post subject: |
|
|
| horntail wrote: | | what is it failing to do? |
Its not moving or deleting, nothing |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|