Solved

How to hide a folder based on file size minimum

Posted on 2010-08-24
4
598 Views
Last Modified: 2012-05-10
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
Comment
Question by:JoshFink
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 2

Assisted Solution

by:roarkinc
roarkinc earned 250 total points
ID: 33514350
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
 
LVL 13

Accepted Solution

by:
soostibi earned 250 total points
ID: 33514385
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
 

Author Comment

by:JoshFink
ID: 33517584
Question -- Does the above Powershell script also hide the main directory? E:\--TV--? If so how do I prevent that?
0
 
LVL 13

Expert Comment

by:soostibi
ID: 33518866
No, it hides only subfolders, but it does not hide subfolders of subfolders.
0

Featured Post

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Utilizing an array to gracefully append to a list of EmailAddresses
A procedure for exporting installed hotfix details of remote computers using powershell
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question