Thread: XP/Vista - renaming, moving & deleting files

  1. #1
    Registered User Tigers!'s Avatar
    Join Date
    Jun 2009
    Location
    Melbourne, Australia
    Posts
    49

    XP/Vista - renaming, moving & deleting files

    Gudday all
    I am slowly finishing off a CSV data file manipulation program.
    About the last step left is rename, moving and delete files.
    After all the work is done I have created 2 files that need to be both renamed and moved, a file that needs to be renamed and 3 files deleted.
    The files to be moved are fortunately to stay on the same HDD but go to different folders.
    (I am rapidly getting of of my depth here)
    I am using rename here.
    Code:
    ..
    if ( rename("C:/ScanImages/Debug/error.dat", "C:/ScanImages/Debug/error.txt") )
          {
    	perror( NULL );
    	getchar();
         }
    ..
    When I run my program I get a permission denied error. See attachment.

    I am not certain what would block my permission as I thought I was in total control.

    Any ideas gratefully accepted (as well as hints for moving and deleting files.)

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    >> I am not certain what would block my permission as I thought I was in total control.

    Are you sure that the destination file doesn't already exist? If so, you'll need to delete it first.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    Registered User
    Join Date
    Mar 2007
    Posts
    416
    What sebastiani said, or the file is already in use/open.

  4. #4
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Since this is Windows, a call to GetLastError() might be more helpful in determinine the specific error that just calling perror().
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  5. #5
    Registered User Tigers!'s Avatar
    Join Date
    Jun 2009
    Location
    Melbourne, Australia
    Posts
    49
    Et al
    I had a closer look at my code and discovered that I was trying to rename the file in question one step before it was closed.
    Once I fixed the code it ran like a charm.
    Thank you for your help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. deleting all files in a directory using c..
    By ShadeS_07 in forum C Programming
    Replies: 6
    Last Post: 07-30-2008, 08:21 AM
  2. deleting files
    By v0id in forum C++ Programming
    Replies: 3
    Last Post: 01-15-2002, 11:29 PM
  3. deleting files not in fstream?
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 10-09-2001, 01:36 PM
  4. Deleting unopened files...
    By Engel32 in forum C++ Programming
    Replies: 3
    Last Post: 09-16-2001, 06:12 PM
  5. deleting files?
    By Paul in forum C++ Programming
    Replies: 6
    Last Post: 09-09-2001, 01:04 AM