Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8075121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:53:15+00:00 2026-06-05T14:53:15+00:00

I have the following code (below) in my app, which simply tries to use

  • 0

I have the following code (below) in my app, which simply tries to use NSTask to touch one file with the directory time/date stamp. It works just fine in an app which only accesses one directory all the time, however, it doesn’t with another that frequently changes directories to access some of it’s data. When I check the currentfile and currentpath they both show the correct paths. I’ve expired every possibility I can think of; any help would be great appreciated — thank you.

- (void)someMethod:(NSString *)currentfile {

    NSFileManager *filemanager = [[NSFileManager alloc] init];

    if ([filemanager changeCurrentDirectoryPath: @"/"] == NO)
    NSLog (@"Cannot change directory.\n");

    NSString *currentpath = [filemanager currentDirectoryPath];
    NSLog (@"Current directory is %@", currentpath);

    [filemanager release];

    NSArray*arguments = [NSArray arrayWithObjects:@"-r",currentpath,currentfile,nil];

    [self touchFiles:arguments];

    return;
}

- (void)touchFiles:(NSArray *)arguments {

    NSTask *task = [[NSTask alloc] init];

    [task setLaunchPath:@"/usr/bin/touch"];

    [task setArguments:arguments];

    [task launch];

    [task release];

    return;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T14:53:16+00:00Added an answer on June 5, 2026 at 2:53 pm

    You can change a file’s modification time without using NSTask. Use -[NSURL setResourceValue:forKey:error:] with the key NSURLContentModificationDateKey.

    As to why your use of NSTask and touch is failing, perhaps you don’t have permissions to modify the file’s modification time. Check the console log to see if any error was reported from touch or redirect the task’s standard error output to someplace else and check that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to know is below code correct ? I have following code which
I have the below code in a .Net 4 Winforms app which loads an
i have the following code below: const char* timeformat = %Y-%m-%d %H:%M:%S; const int
I have the following C# code below. Object first = 5; Object second =
i have the following code: <h3> Your Profile </h3> The information below is what
I have the following code to encrypt a value (listed below). Now I would
I have an Android app which I use to register users on my web
When my app starts for the first time, I have a background process which
I have an iPhone app which uses iAd...The app crashes sometime with the following
I have the following code which worked fine before I implemented jquery mobile. Now,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.