Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copying -- Moving -- and Deleting Files 1

Status
Not open for further replies.

H3RO

Programmer
Jan 8, 2003
12
0
0
LT
Hello. How should I copy or move a file from one directory to another? What are the codes for these commands. I am new to VC so I'm in need of lots help from you guys. I'll appriciate if you could also show me how to delete files as well ~~

(p.s. what should be #included and please, example would be cool)
 
Use the Windows API functions[tt]

CopyFile()
CopyFileEx()
MoveFile()
MoveFileEx()

[/tt]to copy and move files.
Use the ansi C function [tt]remove()[/tt] to delete a file.

[tt]
char* filePath = "someDir\\someFile.txt";
char* newPath = "anotherDir\\someFile.txt";
char* anotherPath = "moveDir\\newFile.txt";

// make a copy of original file
CopyFile(filePath,newPath,FALSE);

// move the copy to another location
MoveFile(newPath,anotherPath);

// delete the original file
remove(filePath);
tellis.gif

[sup]programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.[/sup]​
 
Oh cool :) Thanks for sharing your knowledge with me gednick! btw, were you the one who was helping me with Delay funktions in VC like Sleep ones , but something was wrong with my program and you reccomanded me a book called C++ for Dummys? Anyway, you've been lots of help, couse these functions are the most coolest I wanted to learn. Copying , Moving, and deleting files sure expanded my range of view on the most coolest programming Language the C itself. But,...I still had a little program testing it again...This is like I've wrote, look at it and say what wrong have I did...(please)

void main(){
char* From="C:\\Test.txt";
char* To="D:\\Test.txt";
CopyFile(From,To,FALSE);
}


I don't know what is wrong but I got 2 errors compiling it. #1 - 'CopyFile' : undeclared identifier. #2 - 'FALSE' - undeclared identifier.
 
Delete your current console app and make one that uses MFC. I think you will have all the functionality you will need but if not, search MSDN for copyfile/copyfileex etc and you will see what you need to link with and include.

Matt
 
Oh no that ain't helping...what should I do? And no, my MSDN is not installed till the end or something couse when I'm searching for the info it wants me to add a different CD or something what I don't have...You're my only helpers here . What should I #include<> gednick??
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top