Jump to content
Sign in to follow this  
dhenry123

File Extension Report

Recommended Posts

dhenry123

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

Share this post


Link to post
Share on other sites
DW1

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.

Share this post


Link to post
Share on other sites
dhenry123

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

Share this post


Link to post
Share on other sites
DW1

Look into the following

-FileGetSize

-Recursive Searching

-FileWrite or FileWriteLine

Share this post


Link to post
Share on other sites
PsaltyDS

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

Share this post


Link to post
Share on other sites
dhenry123

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

Share this post


Link to post
Share on other sites
PsaltyDS

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

Share this post


Link to post
Share on other sites
dhenry123

Oh wow! An extra set of eyes has definetely helped! Thank you very much!

Share this post


Link to post
Share on other sites
dhenry123

Oh yes, that is me. I'm a stunter on my free time. That's my 2006 GSXR 750. All white powers Stuntworx cage, subcage and 12 bar. MSR raptor clutch, brembo rear handbrake, dented tank, etc. Just put chrome wheels on it Monday.

Share this post


Link to post
Share on other sites
Foy

or

$LogFile = FileOpen ("C:\TEST\FileExtensionTotalSizeReport.txt", 9)

so if it's not there already you make it and write new stuff on the bottom. :)

Share this post


Link to post
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
Sign in to follow this  

×