Help finding largest file

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
pauljohn
Newbie
Posts: 6
Joined: Mon Feb 22, 2010 3:19 pm
Location: Columbus, OH, USA
Contact:

Help finding largest file

Post by pauljohn » Wed Jan 11, 2012 4:10 pm

I need to find the largest txt from as many as 82 files
The list of txt files are on my c: drive and named file#.txt
Where # could be 1 through 82.
Right not there are 3 files and I need to find the largest of them to process in Access.
It's highly unlikely that there will ever be more then 10 files but I need the flexibility just in case.
There will always be 1 file that is larger.

The file sizes are as follows:
file1.txt = 977332
file2.txt = 1004264
file3.txt = 890090

Getting the FileSize is easy.
The part I'm having trouble with is finding the largest one.
It should be easy but my brain will not cooperate this morning.
This is what I have so far.

let>x=3 //file count from another part of the script, just put here to test
Let>e=1

Repeat>e
FileSize>C:\file%e%.txt,FileSize%e%
Let>f%e%=FileSize%e%
Let>e=e+1
Until>e>x

If>x=1
Let>CF_OVERWRITE=1
CopyFile>C:\file1.txt,u:\file.txt
exit
EndIf

//copy largest file to u:\file.txt

Thank you for your help!

Jerry Thomas
Macro Veteran
Posts: 267
Joined: Mon Sep 27, 2010 8:57 pm
Location: Seattle, WA

Post by Jerry Thomas » Wed Jan 11, 2012 5:07 pm

What about this...

Code: Select all

GetFileList><folder>\*.*,FileList,|
Separate>FileList,|,FileArr

Let>LargestFile=FileArr_1
FileSize>FileArr_1,nFileSize
Let>LargestFileSize=nFileSize

Let>cnt=1
Repeat>cnt
  FileSize>FileArr_%cnt%,nFileSize
  If>nFileSize>LargestFileSize
    Let>LargestFile=FileArr_%cnt%
    Let>LargestFileSize=nFileSize
  Endif
  Let>cnt=cnt+1
Until>cnt,FileArr_Count

MDL>Largest File: %LargestFile%, Size: %LargestFileSize%
Thanks,
Jerry

[email protected]

pauljohn
Newbie
Posts: 6
Joined: Mon Feb 22, 2010 3:19 pm
Location: Columbus, OH, USA
Contact:

You are my hero!

Post by pauljohn » Wed Jan 11, 2012 5:23 pm

Beautifully simple!!
That is exactly what I was wanting to do but I've never worked with arrays before.
It works perfectly on my test set of files.
THANK YOU!!!

pauljohn
Newbie
Posts: 6
Joined: Mon Feb 22, 2010 3:19 pm
Location: Columbus, OH, USA
Contact:

Post by pauljohn » Wed Jan 11, 2012 6:47 pm

My Hero!!
Thank you!
I just tested it with the full script and there were 4 files today.
It picked the correct one and move it over the my server.
This will make 1 more job run with even less user input and get it done quicker.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts