Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 08-11-2010, 12:54 AM   #1 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 55
tobs is on a distinguished road
Default How to delete files with a filename that contains specific string in Documents folder

Hi,

Is it possible to delete files that contains a particular string in their name in the Documents folder?

Example:
In the Documents folder, there are
item1.png
item2.png
item3.png
dog.png
cat.png

I would like to delete only the files that contain the "item" word. So in the example above, i want to delete form the Documents folder the item1.png, item2.png, and item3.png files.

Is this possible? Any inputs would be greatly appreciated.
tobs is offline   Reply With Quote
Old 08-11-2010, 02:32 AM   #2 (permalink)
Registered Member
 
Ice_2k's Avatar
 
Join Date: Apr 2010
Location: Bucharest, Romania
Posts: 148
Ice_2k is on a distinguished road
Default

Code:
NSFileManager* fileManager = [NSFileManager defaultManager];
  
  // get all files in the temp folder
  NSArray* files = [fileManager   contentsOfDirectoryAtPath:NSTemporaryDirectory() error:nil];
  
  // check if it contains my string
  for (int i=0; i<[files count]; i++)
  {
    NSString* fileName = [files objectAtIndex:i];
    if ([fileName rangeOfString:@"StringToSearch"].location != NSNotFound)
      [fileManager removeItemAtPath:[NSString stringWithFormat:@"%@/%@", NSTemporaryDirectory(), fileName] error:nil];
  }
Ice_2k is offline   Reply With Quote
Old 08-11-2010, 02:41 AM   #3 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 55
tobs is on a distinguished road
Default

Quote:
Originally Posted by Ice_2k View Post
Code:
NSFileManager* fileManager = [NSFileManager defaultManager];
  
  // get all files in the temp folder
  NSArray* files = [fileManager   contentsOfDirectoryAtPath:NSTemporaryDirectory() error:nil];
  
  // check if it contains my string
  for (int i=0; i<[files count]; i++)
  {
    NSString* fileName = [files objectAtIndex:i];
    if ([fileName rangeOfString:@"StringToSearch"].location != NSNotFound)
      [fileManager removeItemAtPath:[NSString stringWithFormat:@"%@/%@", NSTemporaryDirectory(), fileName] error:nil];
  }
awesome...i'll go try this...thanks!!
tobs is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 361
9 members and 352 guests
bignoggins, Chickenrig, firecall, givensur, iNet, linkmx, michaelhansen, Objective Zero, PlutoPrime
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,894
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 12:42 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0