Windows Vista Forums

Differences in File Counts (query)
  1. #1



    Junior Member
    Join Date : May 2008
    Darwin, Australia
    Posts : 24
    Vista Ultimate x32
    Local Time: 10:38 PM
    australia au northern territory

    Differences in File Counts (query)

    (Testing on Windows XP Sp2)

    I wonder if anyone can help me with this one.

    I am testing a script as below to be run on our client servers to return the properties of any given directory (specified by client) for pre/post backup comparisons.

    For testing I used the c:\windows directory on my machine simply because it contains a wide variety of file/folder attributes as opposed to standard directories containing just data.

    $FolderList = gc "d:\folderlist.txt"
    $Date = ( get-date ).ToString('yyyy-MM-dd')
    $Report = New-Item -type file "$Date-directory.report.txt"
    ForEach($TargetFolder In $folderlist) {
    $OutItems = (Get-ChildItem $TargetFolder -include *.* -recurse -force | Measure-Object -property length -sum)
    $OutFileNum = @(Get-ChildItem $TargetFolder -recurse -force | ?{!($_.PSIsContainer)}).Count
    $OutFolderNum = @(Get-ChildItem $TargetFolder -recurse -force | ?{$_.PSIsContainer}).Count
    "$TargetFolder : " + "{0:N2}" -f ($OutItems.sum / 1MB) + " MB" + " : Files=$OutFileNum" + " : Folders=$OutFolderNum" |
    out-file $Report -append
    }

    So far I have noticed discrepancies (only very slight) in the returned number of files and folders.

    The script returns the below results for the windows directory.

    c:\windows : 4,516.26 MB : Files=23140 : Folders=2261
    In windows, right-clicking and selecting properties returns this :




    The differences in File and Folder counts is puzzling me. Am I doing something wrong in my script or is there an explanation at the OS level?

    Other directories with 'normal' attributes and content seem to report ok by the way.

      My System SpecsSystem Spec

  2. #2


    RichS [MVP] Guest

    RE: Differences in File Counts (query)

    Couple of thoughts
    Are there any hiiden files\folders that one is picking up and not the other?
    Is the Windows folder itself being counted in one and not the othe?
    Have you tried this on other folders?
    --
    Richard Siddaway
    All scripts are supplied "as is" and with no warranty
    PowerShell MVP
    Blog: http://richardsiddaway.spaces.live.com/
    PowerShell User Group: http://www.get-psuguk.org.uk


    "aukiman" wrote:

    >
    > (Testing on Windows XP Sp2)
    >
    > I wonder if anyone can help me with this one.
    >
    > I am testing a script as below to be run on our client servers to
    > return the properties of any given directory (specified by client) for
    > pre/post backup comparisons.
    >
    > For testing I used the c:\windows directory on my machine simply
    > because it contains a wide variety of file/folder attributes as opposed
    > to standard directories containing just data.
    >
    > $FolderList = gc "d:\folderlist.txt"
    > $Date = ( get-date ).ToString('yyyy-MM-dd')
    > $Report = New-Item -type file "$Date-directory.report.txt"
    > ForEach($TargetFolder In $folderlist) {
    > $OutItems = (Get-ChildItem $TargetFolder -include *.* -recurse -force |
    > Measure-Object -property length -sum)
    > $OutFileNum = @(Get-ChildItem $TargetFolder -recurse -force |
    > ?{!($_.PSIsContainer)}).Count
    > $OutFolderNum = @(Get-ChildItem $TargetFolder -recurse -force |
    > ?{$_.PSIsContainer}).Count
    > "$TargetFolder : " + "{0:N2}" -f ($OutItems.sum / 1MB) + " MB" + " :
    > Files=$OutFileNum" + " : Folders=$OutFolderNum" |
    > out-file $Report -append
    > }
    >
    > So far I have noticed discrepancies (only very slight) in the returned
    > number of files and folders.
    >
    > The script returns the below results for the windows directory.
    >

    > >
    > > c:\windows : 4,516.26 MB : Files=23140 : Folders=2261
    > >
    >
    > In windows, right-clicking and selecting properties returns this :
    >
    > [image:
    > http://i85.photobucket.com/albums/k6...roperties.jpg]
    >
    > The differences in File and Folder counts is puzzling me. Am I doing
    > something wrong in my script or is there an explanation at the OS level?
    >
    > Other directories with 'normal' attributes and content seem to report
    > ok by the way.
    >
    >
    > --
    > aukiman
    >
    > '[image:
    > http://i85.photobucket.com/albums/k6...obranding.gif]'
    > (http://www.radioaukiman.com/forums)
    >

      My System SpecsSystem Spec

  3. #3


    tojo2000 Guest

    Re: Differences in File Counts (query)

    On Jul 30, 4:46*pm, aukiman <gu...@xxxxxx-email.com> wrote:

    > (Testing on Windows XP Sp2)
    >
    > I wonder if anyone can help me with this one.
    >
    > I am testing a script as below to be run on our client servers to
    > return the properties of any given directory (specified by client) for
    > pre/post backup comparisons.
    >
    > For testing I used the c:\windows directory on my machine simply
    > because it contains a wide variety of file/folder attributes as opposed
    > to standard directories containing just data.
    >
    > $FolderList = gc "d:\folderlist.txt"
    > $Date = ( get-date ).ToString('yyyy-MM-dd')
    > $Report = New-Item -type file "$Date-directory.report.txt"
    > ForEach($TargetFolder In $folderlist) {
    > $OutItems = (Get-ChildItem $TargetFolder -include *.* -recurse -force |
    > Measure-Object -property length -sum)
    > $OutFileNum = @(Get-ChildItem $TargetFolder -recurse -force |
    > ?{!($_.PSIsContainer)}).Count
    > $OutFolderNum = @(Get-ChildItem $TargetFolder -recurse -force |
    > ?{$_.PSIsContainer}).Count
    > "$TargetFolder : " + "{0:N2}" -f ($OutItems.sum / 1MB) + " MB" + " :
    > Files=$OutFileNum" + " : Folders=$OutFolderNum" |
    > out-file $Report -append
    >
    > }
    >
    > So far I have noticed discrepancies (only very slight) in the returned
    > number of files and folders.
    >
    > The script returns the below results for the windows directory.
    >
    >
    >

    > > c:\windows : 4,516.26 MB : Files=23140 : Folders=2261
    >
    > In windows, right-clicking and selecting properties returns this :
    >
    > [image:http://i85.photobucket.com/albums/k6...roperties.jpg]
    >
    > The differences in File and Folder counts is puzzling me. Am I doing
    > something wrong in my script or is there an explanation at the OS level?
    >
    > Other directories with 'normal' attributes and content seem to report
    > ok by the way.
    >
    > --
    > aukiman
    >
    > '[image:http://i85.photobucket.com/albums/k6...onmansig-n...]'
    > (http://www.radioaukiman.com/forums)
    So I was fooling around with the code a bit, and after some
    refactoring I seem to be getting better results, but I'm actually not
    sure why yet. I took out the formatting because I was trying to see
    if the way MB was measuring megabytes (1000000 bytes vs 1024^2 bytes),
    and I changed it so that Get-ChildItem is only called once to avoid re-
    scanning directories. I also used tab-separated values because it
    made it easier to open in Excel and suppressed errors from Get-
    ChildItem.

    $FolderList = @(gc 'folderlist.txt')
    $Report = "$((get-date).ToString('yyyy-MM-dd'))-directory.report.txt"

    "`nGetting a list of folders from folderlist.txt...`n"
    "Folder`tSize`tFiles`tFolders`tErrors" > $Report

    ForEach ($TargetFolder In $folderlist) {
    if (-not $TargetFolder) { # skip blank lines
    continue
    }

    $Results = @(Get-ChildItem $TargetFolder -recurse -force -
    ErrorAction 'SilentlyContinue' -ErrorVariable DirErrors)

    $OutItemNum = $Results | Measure-Object -property length -sum
    $OutFileNum = ($Results | ?{$_.PsIsContainer -eq $false}).Count
    $OutFolderNum = ($Results | ?{$_.PsIsContainer -eq $true}).Count

    "$TargetFolder`t$($OutItemNum.sum)`t$OutFileNum`t$OutFolderNum`t$
    ($DirErrors.Count)"
    "$TargetFolder`t$($OutItemNum.sum)`t$OutFileNum`t$OutFolderNum`t$
    ($DirErrors.Count)" >> $Report
    }




      My System SpecsSystem Spec

Differences in File Counts (query) problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
compare two text files and report differences in a text file format Larry__Weiss PowerShell 7 13 Jan 2010
Read from a txt, query AD, write to an xls file? MattW VB Script 3 28 Jul 2009
extract the necessary rowdata from log/txt file from query eventqu tonycd VB Script 2 29 May 2009
Query log file - Cisco PIX Firewall JB PowerShell 4 18 Jan 2007
File counts are wrong..... =?Utf-8?B?V2Fyd2ljayBXZWJi?= Vista file management 1 29 Sep 2006