Jump to content

File Extension Report


Recommended Posts

I have a list of file extensions listed on seperate lines in a TXT file that I need to report back to a log file (CSV or TXT) the following information on seperate lines:

-file extension, total number of files with that extension, total size of files with that extension

Anyone help would be great. Thanks in advance.

Edited by dhenry123
Link to comment
Share on other sites

I have a list of file extensions listed on seperate lines in a TXT file that I need to report back to a log file (CSV or TXT) the following information on seperate lines. Anyone help would be great. Thanks in advance.

-file extension, total number of files with that extension, total size of files with that extension

Didn't you just say you have what you want already? I'm confused

"I have a list of file extensions listed on seperate lines in a TXT file"

"I need to report back to a log file (CSV or TXT) the following information on seperate lines"

You say that you start with a text file with file extensions on seperate lines and then you say that you want a text file with file extensions on seperate lines.

Link to comment
Share on other sites

Didn't you just say you have what you want already? I'm confused

"I have a list of file extensions listed on seperate lines in a TXT file"

"I need to report back to a log file (CSV or TXT) the following information on seperate lines"

You say that you start with a text file with file extensions on seperate lines and then you say that you want a text file with file extensions on seperate lines.

I modified my original posting. Hopefully it is more clear now. See above.

Basically, something like this would be great: http://www.drivemonitor.com/dm/FileExtensionReport.htm

Edited by dhenry123
Link to comment
Share on other sites

I have a list of file extensions listed on seperate lines in a TXT file that I need to report back to a log file (CSV or TXT) the following information on seperate lines:

-file extension, total number of files with that extension, total size of files with that extension

Anyone help would be great. Thanks in advance.

Look up FileFindFirstFile(), FileFindNextFile(), and FileGetSize(), plus loop controls with While/WEnd or Do/Until. Try out the examples given first and then start coding. Post your code if you get stuck, you'll get lots of help writing it, but not much writing it for you.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Ok, i'm stuck. The log file is not being written. See below code.

;
; AutoIt Version: 3.0
; Language:       English
; Platform:       Win2003 Server
; Author:         David Henry
; Orig. Build     10-16-2007
;
; Script Function:
;   IN TEST:  Reports back to log file the total size of files for each current remote user waiting in the Outfiles directory.
;
; Version 1.0   10-16-2007  Original build.

; Verify only one copy of the script is running at a time.
$g_szVersion = "RemoteUserOutfileFileReport"
If WinExists($g_szVersion) Then Exit
AutoItWinSetTitle($g_szVersion)

$ExtensionsFile = FileOpen ( "C:\TEST\FileExtensions.txt", 0) ;File to Read File Extensions from
$LogFile = FileOpen ("C:\TEST\FileExtensionTotalSizeReport.txt", 0) ; File to write results to

While 1
    $FileExtension = FileReadLine($ExtensionsFile)
    If @error = -1 Then ExitLoop
    $FileExtensionTotalSize = "0"
    $SearchFileFindFirstFile = FileFindFirstFile ( "C:\TEST\Data\*." & $FileExtension)
    $IncreaseFileExtensionTotalSize = FileGetSize ($SearchFileFindFirstFile)
    $FileExtensionTotalSize = $FileExtensionTotalSize + $IncreaseFileExtensionTotalSize
    While 1
        $SearchFileFindNextFile = FileFindNextFile ( "C:\TEST\Data\*." & $FileExtension)
        If @error Then ExitLoop
        $IncreaseFileExtensionTotalSize = FileGetSize ($SearchFileFindNextFile)
        $FileExtensionTotalSize = $FileExtensionTotalSize + $IncreaseFileExtensionTotalSize
    WEnd
    FileWrite ($LogFile, "Total file size for file extension " & $FileExtension & " = " & $FileExtensionTotalSize)
    
WEnd

FileClose($ExtensionsFile)
FileClose($LogFile)

Exit
Link to comment
Share on other sites

A couple of things:

1. You opened the log file in READ mode vice write.

2. FileFindFirstFile() returns a HANDLE, that you use to get the files with FileFindNextFile().

3. FileFindNextFile() only returns the file name, without the path.

Minor hints:

a. To increment a variable, you can use a shorthand += operator (as below).

$ExtensionsFile = FileOpen ( "C:\TEST\FileExtensions.txt", 0) ;File to Read File Extensions from
$LogFile = FileOpen ("C:\TEST\FileExtensionTotalSizeReport.txt", 1) ; 1 = append

While 1
    $FileExtension = FileReadLine($ExtensionsFile)
    If @error = -1 Then ExitLoop
    $FileExtensionTotalSize = "0"
    $SearchFileFindFirstFile = FileFindFirstFile ( "C:\TEST\Data\*." & $FileExtension) ; Get search handle
    If @error <> 0 or $SearchFileFindFirstFile = -1 Then ContinueLoop ; Skip to next extension if none found
    While 1
        $SearchFileFindNextFile = FileFindNextFile ($SearchFileFindFirstFile) ; Get next file using search handle
        If @error Then ExitLoop
        $IncreaseFileExtensionTotalSize = FileGetSize ("C:\TEST\Data\" & $SearchFileFindNextFile)
        $FileExtensionTotalSize += $IncreaseFileExtensionTotalSize
    WEnd
    FileWrite ($LogFile, "Total file size for file extension " & $FileExtension & " = " & $FileExtensionTotalSize)
WEnd

FileClose($SearchFileFindFirstFile) ; Close search handle
FileClose($ExtensionsFile)
FileClose($LogFile)

:)

P.S.

b. To avoid carpal tunnel syndrom -- use shorter variable names!

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...