Find All Files Above Certain Size

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
RNIB
Macro Veteran
Posts: 159
Joined: Thu Jan 10, 2008 10:25 am
Location: London, UK

Find All Files Above Certain Size

Post by RNIB » Thu Oct 19, 2017 1:20 pm

I'm trying to write a script that ideally would find all MP3 files in a folder that had a running time of longer than 78 Minutes but because I can't find an easy way of finding the running time I'm resorting to a slightly less accurate method of using file size.

This is what I have at the moment (based on another forum post)

Code: Select all

Let>INPUT_BROWSE=2
Input>Mp3Folder,Please select folder containing MP3 files,
CountFiles>%Mp3Folder%,nCount,0
GetFileList>%Mp3Folder%\*.mp3,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
//Let>MaxByteSize=74882000
If>LargestFileSize>MaxByteSize
MDL>The file %LargestFile% might be longer than 78 Minutes. Please check.
Else
MDL>There are no files longer than 78 Minutes.
Endif

This works fine for finding the largest single file but if there was more than one file that was larger than 74882000 bytes it would only tell you about one of them.

I can't work out how to get it to give me the names of all files that are above that size. The number of files in the source directory is never known in advance and will probably be different each time it's run.

I can't work out whether I should be trying to make FileSize> only look at files above the MaxByteSize or to capture the file size of every file and then compare each against the MaxByteSize

User avatar
JRL
Automation Wizard
Posts: 3501
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Find All Files Above Certain Size

Post by JRL » Thu Oct 19, 2017 4:22 pm

As a starting point, I'd try using DOS forfiles command. The following should give you all files in your chosen folder larger than 74882000 bytes.

Code: Select all

Let>INPUT_BROWSE=2
Input>Mp3Folder,Please select folder containing MP3 files,

Let>RP_Wait=1
Let>RP_Windowmode=0
RunProgram>cmd /c forfiles /p %Mp3Folder% /m *.mp3 /c "cmd /c if @fsize gtr 74882000 echo @file" > %temp_dir%mp3list.txt

ReadFile>%temp_dir%mp3list.txt,vData
MDL>vData

RNIB
Macro Veteran
Posts: 159
Joined: Thu Jan 10, 2008 10:25 am
Location: London, UK

Re: Find All Files Above Certain Size

Post by RNIB » Tue Oct 24, 2017 10:08 am

Cheers JRL, sorry for the long delay in replying. I wasn't ignoring you, just been off work for a few days.

I don't seem to be able to get this to work. I've deliberately put files in a folder that are over size and when I run the script I just get an empty message box come up.

At the risk of sounding dumb, does %temp_dir% mean it gets written to C:\temp or is it more like a virtual temporary folder that is then deleted after the macro finishes? It's just that I can't see a mp3list.txt being created anywhere.

That said I then changed the code to specifically save the mp3list.txt file to c:\temp and when I then ran it the message box just said no file, so I guess it's more that the file isn't being created???

User avatar
JRL
Automation Wizard
Posts: 3501
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Find All Files Above Certain Size

Post by JRL » Tue Oct 24, 2017 12:47 pm

Maybe you don't have the "forfiles" command. What is your operating system? If you open a DOS prompt and type "forfiles /?" what do you see?

Temp_Dir goes to whatever directory your computer has set as the temporary directory. Open Windows File Explorer and type %temp% in the location field near the top of the window and then press enter. You should be directed to where Macro Scheduler sees the Temp_Dir.

RNIB
Macro Veteran
Posts: 159
Joined: Thu Jan 10, 2008 10:25 am
Location: London, UK

Re: Find All Files Above Certain Size

Post by RNIB » Tue Oct 24, 2017 12:57 pm

I'm running Windows 7 64bit.

If I type forfiles into a command prompt I get list of things starting with ".gtk-bookmarks" and ending with "XMLjobtickets"

I've found now where it's creating the .txt file but the file itself is empty which would explain why the message box is blank. I've run this on several different folders that contain files that are much too big but the .txt file is always blank.

RNIB
Macro Veteran
Posts: 159
Joined: Thu Jan 10, 2008 10:25 am
Location: London, UK

Re: Find All Files Above Certain Size

Post by RNIB » Tue Oct 24, 2017 1:49 pm

I think I've found the problem but I don't know why it's a problem.

If I put my large files in C:\temp the script works. For some reason it doesn't like the folder structure we are using which is in this format:

L:\CLIENT NAME BACK CATALOGUE\name\number - Title of production

This it usually is including caps spaces and hyphens

The only other difference is that the L: drive isn't a local drive but a folder on our server that is mapped to a drive letter on each local PC. The actual UNC path would be \\nameofserver\data1\CLIENT NAME BACK CATALOGUE\name\number - Title of production

I can't find there being any folder depth limit to forfiles but neither can I find anything that suggests it can't work with mapped drives :?

RNIB
Macro Veteran
Posts: 159
Joined: Thu Jan 10, 2008 10:25 am
Location: London, UK

Re: Find All Files Above Certain Size

Post by RNIB » Tue Oct 24, 2017 2:20 pm

Okay now I don't know what is going on. Just tried adding subfolders into C:\temp and it wouldn't find any files in any subfolders but now it won't find any files in C:\temp when a moment ago it was :?: :?: :?: Same files, nothing moved, nothing changed in the script. It worked once and now not at all.

User avatar
JRL
Automation Wizard
Posts: 3501
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Find All Files Above Certain Size

Post by JRL » Tue Oct 24, 2017 5:28 pm

Going back to the original script I posted. I see a mistake. If the chosen folder has spaces anywhere in the name the function will find no results unless the path has quotes around it. So I added quotes.

Also remember there will be no results if there are no files larger than 74882000 bytes.

Code: Select all

Let>INPUT_BROWSE=2
Input>Mp3Folder,Please select folder containing MP3 files,

Let>RP_Wait=1
Let>RP_Windowmode=0
RunProgram>cmd /c forfiles /p "%Mp3Folder%" /m *.mp3 /c "cmd /c if @fsize gtr 74882000 echo @file" > %temp_dir%mp3list.txt

ReadFile>%temp_dir%mp3list.txt,vData
MDL>vData

RNIB
Macro Veteran
Posts: 159
Joined: Thu Jan 10, 2008 10:25 am
Location: London, UK

Re: Find All Files Above Certain Size

Post by RNIB » Wed Oct 25, 2017 1:48 pm

Ahh that's fixed it. Working nicely now. Cheers JRL, that's another I owe you.

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