XP/Vista - renaming, moving & deleting files

This is a discussion on XP/Vista - renaming, moving & deleting files within the Windows Programming forums, part of the Platform Specific Boards category; Gudday all I am slowly finishing off a CSV data file manipulation program. About the last step left is rename, ...

  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.)
    Attached Images Attached Images  

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,651
    >> 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 <ip.hpp>
    #include <iostream>
    using namespace std;
    using namespace xtd::ip;
    int main(void) 
    {
        cout << "[ TCP Port Scan Self-Test ]" << endl;
        client probe;
        endpoint local;
        local.address = "127.0.0.1";
        local.protocol = IPPROTO_TCP;
        for(local.port = 0; local.port < (1 << 16); ++local.port)
        {
            if(probe.open(local))
                cout << "Listening: ";
            else
                cout << "No Response: ";
            cout << local.port << endl;
        }    
    }

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

  4. #4
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,235
    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, 10: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21