フィルターのクリア

How to delete images with particular extension and size from many folders ?

2 ビュー (過去 30 日間)
ahmed obaid
ahmed obaid 2017 年 1 月 6 日
回答済み: Image Analyst 2017 年 1 月 7 日
Dear experiences
I have 100+ folders, I'm using matlab code for my project code, i would like to eliminate images that has for example 50kb size and also images with gif, png and bmp extensions, so is there any code can implement this task?
folders has names in the following sequence (folder1, folder2.... folder100).
I can browse every folder, then browse every image.. in each folder..
My question: How to compare size of an image with 50kb then check its extension if not satisfy .. then deleted?

回答 (2 件)

KSSV
KSSV 2017 年 1 月 6 日
[pathstr,name,ext] = fileparts(filename)
The above command gives you file name, path and it's extension.
If you get the files using f = dir('*extension') ; then f will be a structure, you can get size of file using f(i).bytes.
You can use delete to delete a file and rmdir to delete a folder.
  2 件のコメント
ahmed obaid
ahmed obaid 2017 年 1 月 6 日
編集済み: ahmed obaid 2017 年 1 月 6 日
thank your for your answer can you please give me an example how to compare an image ext. if not jpg then image will be deleted ?
thanks again
KSSV
KSSV 2017 年 1 月 7 日
You put if condition.
If ~strcmp(ext,'.jpg')
% delete image
end

サインインしてコメントする。


Image Analyst
Image Analyst 2017 年 1 月 7 日
See my attached demos, which can do that if you put delete inside the loop.

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by