wasabi3689
asked on
how to get the largest file size?
I want to get the largest file size for ".tif" file in a directory including many sub-directories.
How ?
How ?
ASKER
can I get just the largest one? not sort and list all of them
for /f "tokens=1* delims=:" %%a in ('dir *.tif/o:-s/b/s ^| findstr /n .') do if %%a leq 1 echo.%%b
no points: NVIT /od is organize by date /os is by size /o-s shows largest first
@David... Oops. Sorry about that.
@Wasabi... Do you want just the ONE largest out of all found, including subfolders?
Or, do you want the largest of EACH folder?
@Wasabi... Do you want just the ONE largest out of all found, including subfolders?
Or, do you want the largest of EACH folder?
ASKER
Do you want just the ONE largest out of all found, including subfolders?
Yes. I just want the largest .tif file inclduing subfolders
Yes. I just want the largest .tif file inclduing subfolders
A bit of combining (assist) of the above:
@echo off
for /f "delims==" %%a in ('dir *.tif /s /os') do set biggest=%%a
echo %biggest%
ASKER
Gerwin Jansen
This must be a batch file to run?
This must be a batch file to run?
Yes indeed, I assume this isn't a problem?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Here is my batch
I have this error
@echo off
for /f "delims==" %%a in ('\\test3\NGProductionDocs\NGFinalDocs\ICSStorage\*.tif /s /os') do set biggest=%%a
echo %biggest%
pause
I have this error
What error?
All of the BAT examples above use the DIR command and you don't?
All of the BAT examples above use the DIR command and you don't?
ASKER
DO you mean I don't need a full path to the below script?
@echo off
for /f "delims==" %%a in ('dir *.tif /s /os') do set biggest=%%a
echo %biggest%
If I want to check this path \\test3\NGProductionDocs\N GFinalDocs \ICSStorag e, how can I do that?
@echo off
for /f "delims==" %%a in ('dir *.tif /s /os') do set biggest=%%a
echo %biggest%
If I want to check this path \\test3\NGProductionDocs\N
@echo off
for /f "delims==" %%a in ('dir "\\test3\NGProductionDocs\NGFinalDocs\ICSStorage\*.tif" /s /os') do set biggest=%%a
echo %biggest%
pause
ASKER
I have a return like below
0 Dir(s) 10,869,984,972,800 bytes free
Press any key to continue . . .
0 Dir(s) 10,869,984,972,800 bytes free
Press any key to continue . . .
My BAT programming is pretty rusty but I don't think dir /s /os will get you where you want it to. It seems to sort each sub folder's files independent or any other.
a BAT solution would likely involve much more programming.
Did you try the powershell version I posted? Powershell also typically out performs BAT.
a BAT solution would likely involve much more programming.
Did you try the powershell version I posted? Powershell also typically out performs BAT.
Somewhat different from your need, this bat version gets the largest of the folder and it's subfolders:
@echo off
setlocal enabledelayedexpansion
set allfiles=all.txt
dir "*.tif" /s /b /o-s > %allfiles%
for /f "tokens=*" %%a in ('type %allfiles%') do (
set fdv=%%~da
set fndir=%%~pa
set fnamext=%%~nxa
if "!fodir!" equ "" (echo %%~za,!fdv!!fndir!!fnamext!
) else (if "!fndir!" neq "!fodir!" echo %%~za,!fdv!!fndir!!fnamext!
)
set fodir=!fndir!
)
Agree that slightvw's powershell version is so much simpler & easier.
ASKER
NVIT,
your script only shows a list of all files, not indicate which one is the largest one
your script only shows a list of all files, not indicate which one is the largest one
Do you have something against Powershell?
ASKER
Prefer DOS script,
no against PS
if used PS, do you have a simple script to have it?
no against PS
if used PS, do you have a simple script to have it?
>>if used PS, do you have a simple script to have it?
I posted the Powershell code to use back up in: #a41906484
Normally Powershell scripts end with a .PS1 extension.
I posted the Powershell code to use back up in: #a41906484
Normally Powershell scripts end with a .PS1 extension.
ASKER
#a41906484 solution is I need to go to that directory, if I stay in the parent dir and want to look all subfolders, how to modify your PS?
>>solution is I need to go to that directory,
The first command is from current location.
I then posted a second command: "To find the file in c:\temp:"
replace C:\temp with \\test3\NGProductionDocs\N GFinalDocs \ICSStorag e
The first command is from current location.
I then posted a second command: "To find the file in c:\temp:"
replace C:\temp with \\test3\NGProductionDocs\N
ASKER
I put your solution into .PS1 file, I ran it with the following result
PS D:\NGProductionDocs\Config \Maintenan ce> .\FindLargestFilePS.PS1
File D:\NGProductionDocs\Config \Maintenan ce\FindLar gestFilePS .PS1 cannot be loaded because the execution of scripts
disabled on this system. Please see "get-help about_signing" for more details.
At line:1 char:24
+ .\FindLargestFilePS.PS1 <<<<
+ CategoryInfo : NotSpecified: (:) [], PSSecurityException
+ FullyQualifiedErrorId : RuntimeException
PS D:\NGProductionDocs\Config \Maintenan ce>
PS D:\NGProductionDocs\Config
File D:\NGProductionDocs\Config
disabled on this system. Please see "get-help about_signing" for more details.
At line:1 char:24
+ .\FindLargestFilePS.PS1 <<<<
+ CategoryInfo : NotSpecified: (:) [], PSSecurityException
+ FullyQualifiedErrorId : RuntimeException
PS D:\NGProductionDocs\Config
From the powershell prompt try this:
Set-ExecutionPolicy RemoteSigned
Then retry the script.
Set-ExecutionPolicy RemoteSigned
Then retry the script.
> ...your script only shows a list of all files, not indicate which one is the largest one
Here, it shows like...
Here, it shows like...
9059028,c:\test\PSGet_Cmd_All_Full.tif
1174,c:\test\Dir1\CatDumpTestSrc.tif
446237,c:\test\Dir1\Dump\{A414BE00-C782-4039-9E84-F89A2D2E62DA}_1.tif
483606,c:\test\Dir2\DirSiz-2016_04_08.tif
9059028,c:\test\Dir3\PSGet_Cmd_All_Full.tif
189,c:\test\Dir3\combine\2.tif
>>Here, it shows like...
The requirement is: From the starting folder and sub folders return the ONE SINGLE largest file.
It isn't to return the largest in each folder.
The requirement is: From the starting folder and sub folders return the ONE SINGLE largest file.
It isn't to return the largest in each folder.
I know that netminder. As I posted with the code. No worries.
ASKER
Expert Commentby:slightwv (䄆 Netminder) or other expoerts
I ran your PS script, it works to capture the largest files. But, now I want to make some changes. If I want two groups 1. files larger than 20MB, and group larger than between 10 MB and 20 MB, how to modify it. I want to list all the files for each group.
Here is my PS script
I ran your PS script, it works to capture the largest files. But, now I want to make some changes. If I want two groups 1. files larger than 20MB, and group larger than between 10 MB and 20 MB, how to modify it. I want to list all the files for each group.
Here is my PS script
Get-ChildItem -recurse F:\NGProductionDocs\NGSourceDocs\ICSStorage | Where-Object {$_.Extension -eq ".tif"} | Sort Length -desc | Select-Object -first 1
That should be a new related question.
Before asking the new question, I would also suggest looking around on the Internet to see if there is a way to check sizes.
The first thing I would check is the Where-Object that is restricting the file types. Maybe there is a way to also restrict based on the size or length of the object.
I would guess since you need two outputs, there would need to be two different commands.
Before asking the new question, I would also suggest looking around on the Internet to see if there is a way to check sizes.
The first thing I would check is the Where-Object that is restricting the file types. Maybe there is a way to also restrict based on the size or length of the object.
I would guess since you need two outputs, there would need to be two different commands.
ASKER
two commands or two PS batch files are fine. So, how to check file size in PS?
>>So, how to check file size in PS?
Again, that needs to be a new question.
Again: Before asking the new question, read what I posted... everything you need to answer this yourself is in that post.
Again, that needs to be a new question.
Again: Before asking the new question, read what I posted... everything you need to answer this yourself is in that post.
Open in new window