Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 616
  • Last Modified:

How to hide a folder based on file size minimum

Hello, I'm hoping someone can help me out.

I'm trying to figure out how to hide folders whose contents are less than 200mb in size. I want to run this script on a schedule and have it

Scan the directory E:\--TV--\

Cycle through each top level folder in the directory and determine folder contents space

< 200mb in size = Hide
> 201mb in size = Visible

Can someone point me in the right direction or help out?

Thanks

Josh
0
JoshFink
Asked:
JoshFink
  • 2
2 Solutions
 
roarkincCommented:
you can do this with a batch script

this will get you the folder size including subfolders:

@For /F "tokens=*" %%a IN ('"dir /s /-c | find "bytes" | find /v "free""') do @Set summaryout=%%a
@Echo %summaryout%
@For /f "tokens=1,2 delims=)" %%a in ("%summaryout%") do @set filesout=%%a&set sizeout=%%b
@Echo %filesout%
@Echo %sizeout%
@Set sizeout=%sizeout:bytes=%
@Echo %sizeout%
@Set sizeout=%sizeout: =%
@Echo Size is :%sizeout%

this is what you can use to hide the folder

attrib +h folderName

to unhide us
attrib -h folderName
0
 
soostibiCommented:
This is PowerShell solution:
$fs = New-Object -ComObject scripting.filesystemobject
Get-ChildItem E:\--TV--\ -force | Where-Object {$_.psiscontainer} | ForEach-Object {
	if($fs.getfolder($_.fullname).size -lt 200mb) {$_.attributes = "directory,hidden"}
	else{$_.attributes = "directory"}
}

Open in new window

0
 
JoshFinkAuthor Commented:
Question -- Does the above Powershell script also hide the main directory? E:\--TV--? If so how do I prevent that?
0
 
soostibiCommented:
No, it hides only subfolders, but it does not hide subfolders of subfolders.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now