| Index | Submit class | Submit snippet | Submission feed | List |

NSWorkspace (BSDriveRecognition)

Language: Objective-C, Author: Michele Balistreri
License: Public domain

This NSWorkspace category allows you to discern between mounted physical volumes and network volumes. Please note that currently only webdav volumes are recognized as network drives, however this can be easily fixed by simply adding some string comparisons at the end of the -isNetworkVolumeAtPath: which the desired network volumes.

NSWorkspace (BSDriveRecognition) source preview

#import "NSWorkspace+BSDriveRecognition.h"

@implementation NSWorkspace (BSDriveRecognition)

- (NSArray *)mountedPhysicalVolumes
{
  NSMutableArray *volumes = [NSMutableArray array];
  NSEnumerator *enu = [[self mountedLocalVolumePaths] objectEnumerator];
  NSString *mountPath;
  
  while((mountPath = [enu nextObject]))
  {
    if(![self isNetworkVolumeAtPath:mountPath])
    {
      [volumes addObject:mountPath];
    }
  }
  
  return [NSArray arrayWithArray:volumes];
}

- (BOOL)isNetworkVolumeAtPath:(NSString *)path
{
  struct statfs buffer;
  NSString *fileSystemType = nil;
  if(statfs([path fileSystemRepresentation], &buffer) == 0)
  {
    fileSystemType = [NSString stringWithCString:buffer.f_fstypename];
  }
  
  return [fileSystemType isEqualToString:@"webdav"];
}

@end

NSWorkspace (BSDriveRecognition) header preview

#import <Cocoa/Cocoa.h>
#include <sys/param.h>
#include <sys/mount.h>

@interface NSWorkspace (BSDriveRecognition)

- (NSArray *)mountedPhysicalVolumes;
- (BOOL)isNetworkVolumeAtPath:(NSString *)path;

@end
Download Archive

Compatible with:


Comments

Name

Website

Do you hate spammers? (Answer "Yes")