Specialty Forums
Security and Virus
General Hardware
CPUs/Overclocking
Networking
Digital Photo/Video
Office Software
PC Gaming
Console Gaming
Programming
Database
Web Development
Digital Home

General Forums
Windows XP
Windows Vista
Windows 95/98
Windows Me
Windows NT
Windows 2000
Win Server 2008
Win Server 2003
Windows 3.1
Linux
PDAs
BeOS
Novell Netware
OpenVMS
Solaris
Disk Op. System
Unix
Mac
OS/2

Drivers
Driver Scan
Driver Forum

Software
Automatic Updates

BIOS Updates

My Computing.Net

Solution Center

Free IT eBook

Howtos

Site Search

Message Find

RSS Feeds

Install Guides

Data Recovery

About

Home
Reply to Message Icon Go to Main Page Icon

C++ copy / delete file

Original Message
Name: tImmaY
Date: July 14, 2004 at 09:26:24 Pacific
Subject: C++ copy / delete file
OS: Windows XP Pro SP1
CPU/Ram: AMD Athlon XP 2400+/512 m
Comment:
Hello, I'm wondering how I could copy and then delete a file in C++. What I want to do is copy a file, then delete the original so that i can encrypt it and name it the original file. then i want to delete the temp file. but the only things i need to know are how to copy and then delete a file, i have all of the encryption already. thanks! ::tim

Report Offensive Message For Removal


Response Number 1
Name: tImmaY
Date: July 14, 2004 at 09:51:33 Pacific
Subject: C++ copy / delete file
Reply: (edit)
*ahh..* the joys of batch commands in C++ programming..
also..*ahh*..the joys of stumbling across something after posting a question on a forum about it.

anyways, to copy its just:
system("copy shibby.txt temp.txt");

to delete:
system("del shibby.txt");

lol yea.. that was too easy..


Report Offensive Follow Up For Removal

Response Number 2
Name: Don Arnett
Date: July 14, 2004 at 10:38:57 Pacific
Subject: C++ copy / delete file
Reply: (edit)
It would be more efficient to:

- rename the original file
- read the renamed file and write encrypted file to original file name
- delete the renamed file


File I/O functions are specific to compilers, so you'll need to check your docs to see what file handling functions it has.

You should have a 'system()' function which allows you to run DOS-like commands. For example:

char cmdBuff[200];

sprintf(cmdBuff,"rename %s %s",origFileName,newFileName);
system(cmdBuff);

For deleting a file, look for an 'unlink()' function.


Report Offensive Follow Up For Removal

Response Number 3
Name: Don Arnett
Date: July 14, 2004 at 10:40:26 Pacific
Subject: C++ copy / delete file
Reply: (edit)
I started typing my answer, then was interrupted and then when to lunch. Meanwhile, you found the system command.

I'd still suggest that you should rename rather copy/delete.


Report Offensive Follow Up For Removal

Response Number 4
Name: tImmaY
Date: July 15, 2004 at 07:58:23 Pacific
Subject: C++ copy / delete file
Reply: (edit)
ic ic, lol. its all good.. :)

but aren't they essentially doing the same thing? only with renaming i'm creating a new file and then deleting the original instead of copying then deleting the original. i'm not sure which would be more efficient but i've gotten everything to work and i'm happy with it. now i just get to make things more complicated.. but you can look at it if you want. its either in a previous post i made (2 of mine ago) or you can download it from: http://www.freewebs.com/anarchy85/thelist.cpp


Report Offensive Follow Up For Removal

Response Number 5
Name: Don Arnett
Date: July 15, 2004 at 18:45:35 Pacific
Subject: C++ copy / delete file
Reply: (edit)

Renaming is not the same as creating a new file, copying the old file into the new file and deleting the old file.

In any file system, a file consists of two things (this is a simplified example).

First, there is the file, which is a bunch of bytes stored in a group on the harddrive.

Second, there is an entry in a table for that file. The entry contains info like the file location, creation date, file name, maybe it's size, etc.

Normally, when you rename, all that happens is the OS goes to that file's entry in the table and changes the name. The actual file doesn't get touched. Why move the file around when all you have to do is change the label.

Now, there are cases where a rename will cause a file to get copied and the original deleted. When the rename causes the file to move from one disk device to another.

I don't know if this is legal in Windows, but it'll make the point.

rename C:\myfileA.txt D:\myfileB.txt

Each drive keeps it's own table of file info. So changing the entry in the file table on drive C doesn't cause the file to be moved to D. So even tho all you told it to do was a rename, the OS will be smart enough to do a copy to the new name on the new drive and delete the old file on the old drive.

I don't know if windows will do that, but other operating systems will do that.


Report Offensive Follow Up For Removal


Response Number 6
Name: tImmaY
Date: July 15, 2004 at 23:47:20 Pacific
Subject: C++ copy / delete file
Reply: (edit)
hmm.. ya make a good point kid. it would make more sense to just rename it.. i wonder if i should defrag soon because it seems that the way i've been doing it would create the new file in a bunch of locations on my hard drive just to delete them. so that new files that i put on my hard drive would be somewhere off in lala land. idk, i'm not a guru of any sort so i'm just talking out of my bum so i'll shut up now. :) thanks

Report Offensive Follow Up For Removal



Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: C++ copy / delete file

Comments:

 
  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 


Data Recovery Software




acer 312T BIOS problem

K7 Turbo possible max fsb?

Pc anywher problem

WinFLP & OE/Outlook2003

Computer resets after a few minutes


The information on Computing.Net is the opinions of its users. Such opinions may not be accurate and they are to be used at your own risk. Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE

All content ©1996-2007 Computing.Net, LLC