0

I am using NStask to get the folder size.Its working fine for normal file paths like home/ABC/Users/testUser/Documents. But it is not showing any output for file path like home/ABC/Users/testUser/Ω≈ç∂√√√∂ƒ∂.However I am getting proper output for the same file path on terminal. Any suggestion?

    NSString* userName = @"test123_test123";
    NSString* password = @"test";
    NSString* serverIP = @"200.144.172.210";
    NSString* sizeFolderPath = [[NSBundle mainBundle] pathForResource:@"demoUtilities" ofType:nil];

    NSString* xml= @"--test";
    NSString* passwordArg = [NSString stringWithFormat:@"--pwd-=%@",password];

    NSString *filePath = @"UsersMac/Users/test/Ω≈ç∂√√√∂ƒ∂";
    NSString* address = [NSString stringWithFormat:@"%@@%@::home/%@", userName,   serverIP,filePath];
    NSArray* arguments = [NSMutableArray arrayWithObjects:xml,passwordArg,address,nil];

    TestCommandExcecuter *cmExec = [[TestCommandExcecuter alloc]init];
    [cmExec setCommandString:sizeFolderPath];
    [cmExec setCommandArguments:arguments];
Akhil Shrivastav
  • 427
  • 3
  • 13
  • 1
    please share the code u r using to fetch file size so that it can be cross checked.. :) – Swati Jun 13 '14 at 06:05
  • please have a look @this link : http://stackoverflow.com/questions/23816347/cannot-pass-special-characters-to-an-nstask >> hope it gives a clue – Swati Jun 13 '14 at 06:54
  • can't see the command you are using in `NSTask` not even the `NSTask` variable also in the sample code? BTW if you use `du` command in `NSTask` it might do the trick – bikram990 Jun 16 '14 at 06:25
  • you can use `du -c |tail -1` in `NSTask` and then parse the output. – bikram990 Jun 16 '14 at 06:29

1 Answers1

1

I am using this code:

Depricated from 2.0

 NSDictionary *fileDictionary = [[NSFileManager defaultManager]   
                                    fileAttributesAtPath:filePath traverseLink:YES];

long long size = [fileDictionary fileSize];
 NSLog(@"size :: %lld",size);

Latest :

 NSDictionary *fileDictionary = [[NSFileManager defaultManager] 
                                     attributesOfItemAtPath:filePath error:nil];

long long size = [fileDictionary fileSize];
NSLog(@"size :: %lld",size);

Here is the reference link :

https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSFileManager_Class/Reference/Reference.html#//apple_ref/occ/instm/NSFileManager/attributesOfItemAtPath%3aerror%3a

Swati
  • 2,870
  • 7
  • 45
  • 87