hii,
im using Loop, C:\*.*, , 1 and C:\ += %A_LoopFileSize% to get the total size of C:\ Drive.
however i want to exclude some folders like c:\windows and c:\program files from the loop so these folders will not counting in the total size.
tell me if you need the full code to help me figure this out..
tnx!
Help with exclude folders from loop Topic is solved
Re: Help with exclude folders from loop
Try adding the following to the top of your loop (inside your loop, but before file size computation):
Continue makes it skip the rest of the loop, but move the file pointer and start again from the top.
Code: Select all
If RegExMatch(A_LoopFileLongPath, "C:\\Program Files") or RegExMatch(A_LoopFileLongPath, "C:\\Windows")
Continue
Re: Help with exclude folders from loop
Thanks Osprey but i failed to make it work,
i added the full code below, may you take a look.
tnx!
i added the full code below, may you take a look.
tnx!
Code: Select all
C_Drive = C:\
; C_Drive size
Loop, %C_Drive%\*.*, , 1
C_DriveSize += %A_LoopFileSize%
; in KB
KB_C_Drive := Round(((C_DriveSize /1024)), 0)
; in MB
MB_C_Drive := Round(((C_DriveSize /1024)/1024), 2)
; in GB
GB_C_Drive := Round(((C_DriveSize /1024)/1024/1024), 2)
if KB_C_Drive = 0
{
MsgBox, empty
}
else
if KB_C_Drive < 1024
{
MsgBox, %KB_C_Drive% KB
}
else if MB_C_Drive > 1024
{
MsgBox, %GB_C_Drive% GB
}
else
{
MsgBox, %MB_C_Drive% MB
}
Re: Help with exclude folders from loop
Try this:
Code: Select all
Loop, %C_Drive%\*.*, , 1
If !(RegExMatch(A_LoopFileLongPath, "i)C:\\Program Files") or RegExMatch(A_LoopFileLongPath, "i)C:\\Windows") or RegExMatch(A_LoopFileLongPath, "i)C:\\\$Recycle.Bin"))
C_DriveSize += %A_LoopFileSize%
Re: Help with exclude folders from loop
i still get the same total size
Re: Help with exclude folders from loop
- How about this?
- Some methods for this that I've seen, loop through every file on the drive, but just don't increment the variables for paths that contain certain strings. Which is clearly slower than it needs to be. (It's better to not loop through the folders that you want to exclude.)
Code: Select all
q:: ;list number/size of files on C drive
vDir1 := "C:"
vList := ""
Loop, Files, % vDir1 "\*", D
{
if !(A_LoopFileName = "Windows")
&& !InStr(A_LoopFileName, "Program Files")
vList .= A_LoopFileFullPath "|"
}
vList := SubStr(vList, 1, -1)
MsgBox, % StrReplace(vList, "|", "`n")
vCount := 0, vSize := 0
Loop, Parse, vList, |
Loop, Files, % A_LoopField "\*", FR
vCount += 1, vSize += A_LoopFileSize
MsgBox, % vCount " " vSize
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: Help with exclude folders from loop
As jeeswg suggested, try using the newer syntax for looping files, assuming that you have a recent version of AutoHotkey.
Here's the simplest code that works for me:
Here's the simplest code that works for me:
Code: Select all
C_Drive = C:\
ExcludeList = C:\Program Files,C:\Windows,C:\$Recycle.Bin
Loop, Files, %C_Drive%\*.*, R
If A_LoopFileLongPath not contains %ExcludeList%
C_DriveSize += %A_LoopFileSize%
Re: Help with exclude folders from loop
sorry for the late reply,
tnx Osprey & jeeswg. now it works great!
tnx Osprey & jeeswg. now it works great!
Re: Help with exclude folders from loop
I have written some code re. displaying a friendly file size, using the Winapi, and via pure AHK:
Floor/Ceil able to handle decimal places (cf. Excel's Trunc function) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 77#p189277
WinAPI - GetXxxFormat Functions - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 76#p189276
Floor/Ceil able to handle decimal places (cf. Excel's Trunc function) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 77#p189277
WinAPI - GetXxxFormat Functions - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 76#p189276
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: Help with exclude folders from loop
ok so thanks to your help i came up with the following code,
2 questions please:
1. i want to show and exclude files aswell, should i really need looping the drive 2 times for this ?
2. i failed to exclude files extensions, need help with that too (in my code sample im trying to exclude .txt and .exe extensions)
2 questions please:
1. i want to show and exclude files aswell, should i really need looping the drive 2 times for this ?
2. i failed to exclude files extensions, need help with that too (in my code sample im trying to exclude .txt and .exe extensions)
Code: Select all
vDir1 := "C:"
vList := ""
Loop, Files, % vDir1 "\*", D ; folders
{
if !(A_LoopFileName = "Windows")
&& !InStr(A_LoopFileName, "Users") && !InStr(A_LoopFileName, "Program Files") && !InStr(A_LoopFileName, "ProgramData") && !InStr(A_LoopFileName, "$Recycle.Bin")
vList .= A_LoopFileFullPath "|"
}
Loop, Files, % vDir1 "\*", F ; files
{
if !(A_LoopFileName = "*.txt")
&& !InStr(A_LoopFileName, "*.exe")
vList .= A_LoopFileFullPath "|"
}
vList := SubStr(vList, 1, -1)
MsgBox, % StrReplace(vList, "|", "`n")
TotalSize := 0
Loop, Parse, vList, |
Loop, Files, % A_LoopField "\*", FR
TotalSize += %A_LoopFileSize%
; in KB
KB_Drive := Round(((TotalSize /1024)), 0)
; in MB
MB_Drive := Round(((TotalSize /1024)/1024), 2)
; in GB
GB_Drive := Round(((TotalSize /1024)/1024/1024), 2)
if KB_Drive = 0
{
MsgBox, empty
}
else
if KB_Drive < 1024
{
MsgBox, %KB_Drive% KB
}
else if MB_Drive > 1024
{
MsgBox, %GB_Drive% GB
}
else
{
MsgBox, %MB_Drive% MB
}
ExitApp
Re: Help with exclude folders from loop
Code: Select all
;this won't work, a = b compares literal text,
;it cannot handle wildcards (i.e. ? or *):
if !(A_LoopFileName = "*.txt")
&& !InStr(A_LoopFileName, "*.exe")
;so do this instead:
if !(A_LoopFileExt = "txt")
&& !(A_LoopFileExt = "exe")
;with looping, if you loop through the list of
;folders, that won't include files on the root of C,
;so add one loop for those:
vDir1 := "C:"
TotalSize := 0
Loop, Files, % vDir1 "\*", F
TotalSize += A_LoopFileSize
MsgBox, % TotalSize
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: Help with exclude folders from loop
Jeeswg ty! will check it
UPDATE:
I came up with this and its working fine,
one problem now that files stored in C:\ not include in the total size (only folders)
i see you added something about this but couldnt understand it..
also, im still using 2 separate loops for folders and files
folders: Loop, Files, % vDir1 "\*", D
Files: Loop, Files, % vDir1 "\*", F
dunno if it could be 1 loop for both folders and files..
if you can post your full code suggestion i'll be thankful
tnx!
UPDATE:
I came up with this and its working fine,
one problem now that files stored in C:\ not include in the total size (only folders)
i see you added something about this but couldnt understand it..
also, im still using 2 separate loops for folders and files
folders: Loop, Files, % vDir1 "\*", D
Files: Loop, Files, % vDir1 "\*", F
dunno if it could be 1 loop for both folders and files..
if you can post your full code suggestion i'll be thankful
tnx!
Code: Select all
vDir1 := "C:"
vList := ""
Loop, Files, % vDir1 "\*", D ; folders
{
if !(A_LoopFileName = "Windows")
&& !InStr(A_LoopFileName, "Users") && !InStr(A_LoopFileName, "Program Files") && !InStr(A_LoopFileName, "ProgramData") && !InStr(A_LoopFileName, "$Recycle.Bin")
vList .= A_LoopFileFullPath "|"
}
Loop, Files, % vDir1 "\*", F ; files
{
if !(A_LoopFileExt = "txt")
&& !(A_LoopFileExt = "exe")
vList .= A_LoopFileFullPath "|"
}
vList := SubStr(vList, 1, -1)
MsgBox, % StrReplace(vList, "|", "`n")
TotalSize := 0
Loop, Parse, vList, |
Loop, Files, % A_LoopField "\*", FR
TotalSize += %A_LoopFileSize%
; in KB
KB_Drive := Round(((TotalSize /1024)), 0)
; in MB
MB_Drive := Round(((TotalSize /1024)/1024), 2)
; in GB
GB_Drive := Round(((TotalSize /1024)/1024/1024), 2)
if KB_Drive = 0
{
MsgBox, empty
}
else
if KB_Drive < 1024
{
MsgBox, %KB_Drive% KB
}
else if MB_Drive > 1024
{
MsgBox, %GB_Drive% GB
}
else
{
MsgBox, %MB_Drive% MB
}
ExitApp
Last edited by Tomer on 24 Dec 2017, 04:36, edited 6 times in total.
Re: Help with exclude folders from loop
I suggest making array or two arrays (for paths and files) to be excluded, and then use continue in loop to skip element upon matching thing from array, rather than making big ifs. Depends on your need really.
Use
Code: Select all
[/c] forum tag to share your code.
Click on [b]✔[/b] ([b][i]Accept this answer[/i][/b]) on top-right part of the post if it has answered your question / solved your problem.
Re: Help with exclude folders from loop Topic is solved
@Tomer: Think about this:
C:\Dir1 C:\Dir2 C:\Dir3 C:\File1 C:\File2 C:\File3
1) List folders on the root of C, but exclude Dir2. 1 loop.
C:\Dir1 C:\Dir3
2) Get the size of the files on the root of C. 1 loop.
3) For each folder in the list folders, get the size of all files. A file loop within a parsing loop.
Think through the script below until it fully makes sense to you.
C:\Dir1 C:\Dir2 C:\Dir3 C:\File1 C:\File2 C:\File3
1) List folders on the root of C, but exclude Dir2. 1 loop.
C:\Dir1 C:\Dir3
2) Get the size of the files on the root of C. 1 loop.
3) For each folder in the list folders, get the size of all files. A file loop within a parsing loop.
Think through the script below until it fully makes sense to you.
Code: Select all
vDir1 := "C:"
vList := ""
Loop, Files, % vDir1 "\*", D ; folders
{
if !(A_LoopFileName = "Windows")
&& !InStr(A_LoopFileName, "Users") && !InStr(A_LoopFileName, "Program Files") && !InStr(A_LoopFileName, "ProgramData") && !InStr(A_LoopFileName, "$Recycle.Bin")
vList .= A_LoopFileFullPath "|"
}
vList := SubStr(vList, 1, -1)
MsgBox, % StrReplace(vList, "|", "`n")
TotalSize := 0
Loop, Files, % vDir1 "\*", F ; files
if !(A_LoopFileExt = "txt")
&& !(A_LoopFileExt = "exe")
TotalSize += A_LoopFileSize
Loop, Parse, vList, |
Loop, Files, % A_LoopField "\*", FR
if !(A_LoopFileExt = "txt")
&& !(A_LoopFileExt = "exe")
TotalSize += A_LoopFileSize
; in KB
KB_Drive := Round(((TotalSize /1024)), 0)
; in MB
MB_Drive := Round(((TotalSize /1024)/1024), 2)
; in GB
GB_Drive := Round(((TotalSize /1024)/1024/1024), 2)
if KB_Drive = 0
{
MsgBox, empty
}
else
if KB_Drive < 1024
{
MsgBox, %KB_Drive% KB
}
else if MB_Drive > 1024
{
MsgBox, %GB_Drive% GB
}
else
{
MsgBox, %MB_Drive% MB
}
ExitApp
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: Help with exclude folders from loop
Thanks jeeswg works like a charm!
only 1 thing: now the MsgBox, % StrReplace(vList, "|", "`n") shows only the folders (not files aswell ) before it gives the total size,
i fixed it with the code added, but if you have fatser method it'll be great!
only 1 thing: now the MsgBox, % StrReplace(vList, "|", "`n") shows only the folders (not files aswell ) before it gives the total size,
i fixed it with the code added, but if you have fatser method it'll be great!
Code: Select all
vDir1 := "C:"
vList := ""
Loop, Files, % vDir1 "\*", D ; folders
{
if !(A_LoopFileName = "Windows")
&& !InStr(A_LoopFileName, "Users") && !InStr(A_LoopFileName, "Program Files") && !InStr(A_LoopFileName, "ProgramData") && !InStr(A_LoopFileName, "$Recycle.Bin")
vList .= A_LoopFileFullPath "|"
}
Loop, Files, % vDir1 "\*", F ; files
{
if !(A_LoopFileExt = "txt")
&& !(A_LoopFileExt = "exe")
vList .= A_LoopFileFullPath "|"
}
vList := SubStr(vList, 1, -1)
MsgBox, % StrReplace(vList, "|", "`n")
TotalSize := 0
Loop, Files, % vDir1 "\*", F ; files
if !(A_LoopFileExt = "txt")
&& !(A_LoopFileExt = "exe")
TotalSize += A_LoopFileSize
Loop, Parse, vList, |
Loop, Files, % A_LoopField "\*", FR
if !(A_LoopFileExt = "txt")
&& !(A_LoopFileExt = "exe")
TotalSize += A_LoopFileSize
; in KB
KB_Drive := Round(((TotalSize /1024)), 0)
; in MB
MB_Drive := Round(((TotalSize /1024)/1024), 2)
; in GB
GB_Drive := Round(((TotalSize /1024)/1024/1024), 2)
if KB_Drive = 0
{
MsgBox, empty
}
else
if KB_Drive < 1024
{
MsgBox, %KB_Drive% KB
}
else if MB_Drive > 1024
{
MsgBox, %GB_Drive% GB
}
else
{
MsgBox, %MB_Drive% MB
}
ExitApp
Re: Help with exclude folders from loop
- vList is supposed to be a list of folders, without any files in it. I would create a separate variable for displaying the list of folders/files on the root of C. I don't know why exactly you would want to display a list of some of the files/folders on the root of C.
- I would just get rid of the MsgBox, I only put the MsgBox there for diagnostic reasons, so that you would know which folders would be looped through, and to show that certain folders would be omitted from the search.
- In terms of 'faster', listing the files on the root of C, should hardly take any time.
- I would just get rid of the MsgBox, I only put the MsgBox there for diagnostic reasons, so that you would know which folders would be looped through, and to show that certain folders would be omitted from the search.
- In terms of 'faster', listing the files on the root of C, should hardly take any time.
Code: Select all
vList2 := vList
Loop, Files, % vDir1 "\*", F ; files
{
if !(A_LoopFileExt = "txt")
&& !(A_LoopFileExt = "exe")
vList2 .= A_LoopFileFullPath "|"
}
vList2 := SubStr(vList2, 1, -1)
MsgBox, % StrReplace(vList2, "|", "`n")
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: Help with exclude folders from loop
i want to display a list of the folders and files which i not exluded,
so i know what the total size i get for.
its ok as it is now thank you very much
so i know what the total size i get for.
its ok as it is now thank you very much
Who is online
Users browsing this forum: No registered users and 272 guests