An old compiled app suddenly doesn’t work. No idea why so I attempt to convert from ASS to ASOC.
Opening and reading (writing and closing) text files should be easy but this is C, so it’s next to impossible. The old Finder commands I used don’t seem to work so I attempt to simply open a file and read it as a string. No problem? Wrong!
I already have a sublcass of NSObject I call NSHack. I have successfully used fileExistsAtPath:isDirectory: by passing an NSString to it through ASHack.
- (NSArray *) myFileExistsAtPath:(NSString *)path
{
NSFileManager *fileManager = [NSFileManager defaultManager];
BOOL isDir = YES;
BOOL theResult = [fileManager fileExistsAtPath:path isDirectory:&isDir];
NSString *bool1;
NSString *bool2;
if (theResult == YES)
{
bool1 = [NSString stringWithString:@"YES"];
}
else
{
bool1 = [NSString stringWithString:@"NO"];
}
if (isDir == YES)
{
bool2 = [NSString stringWithString:@"YES"];
}
else
{
bool2 = [NSString stringWithString:@"NO"];
}
NSArray *theArray = [NSArray arrayWithObjects:bool1, bool2, nil];
return theArray;
}
property ASHack : class "ASHack" of current application
set theResult to ASHack's myFileExistsAtPath_(thePath)
No problem here at all. However, attempting to pass the same, valid, path to ASHack’s read file always gives an error.
Emptying the routine of all statements except an NSLog still gives the error message.
- (NSString *) myReadFile:(NSString *)path
{
NSLog(@"myReadFile");
NSStringEncoding encoding = NSUTF8StringEncoding;
NSFileHandle *file = [[NSFileHandle fileHandleForReadingAtPath:path] retain];
NSData *theData = [file readDataToEndOfFile];
NSString *dataStr = [[NSString alloc] autorelease];
dataStr = [dataStr initWithData:theData encoding];
return dataStr;
}
What is going wrong here?
There must be a better way to access the simple text of a text document “ please help.