Solved

copy & renaming files using win32 API

Posted on 1997-09-07
4
1,033 Views
Last Modified: 2010-07-27
Does anyone have an example(v.simple) of
    a. find file on a lan (fp = FindFileFirst(fid, class) )?
    b  copy to another dir () ?
    c  rename original file () ?

P.S. This used to be very simple. like call sys()!
0
Comment
Question by:rabit
  • 2
  • 2
4 Comments
 
LVL 1

Accepted Solution

by:
ohell earned 25 total points
Comment Utility
a. This has two simple steps: Suppose I want to find a file called pet.rabit in a share called rabit_cage on the machine farm. I have to do the following
  {
   WIN32_FIND_DATA fileData;
   HANDLE h = FindFirstFileW(“\\?\UNC\farm\rabit_cage\pet.rabit”,                             &fileData);
   if (h == INVALID_HANDLE_VALUE) throw CFileNotFoundException;
   FindClose(h);
  }
Now fileData has the required file information; CFileNotFoundException is a CException derived class for error handling.

b. Now I'm copying pet.rabit to rabit.pet
  {
   CopyFile(“\\?\UNC\farm\rabit_cage\pet.rabit”,                          “\\?\UNC\farm\rabit_cage\rabit.pet”);
  }

c. Use MoveFile(), syntax same as CopyFile();

To check for errors, you have to use GetLastError(). Also, copy and move have counterparts CopyFileEx() & MoveFileEx() that add some bells and whistles to the basic functions. Oh, and FindFirstFileW() works only on NT, though I assume FindFirstFile() would be adequate on 95, I have never tried it.

Hope this helps...
0
 

Author Comment

by:rabit
Comment Utility
Thanks, I'll get the hang of NT sooner or later!
0
 
LVL 1

Expert Comment

by:ohell
Comment Utility
oops, going ver the question again, I see that I have goofed up doing cut and paste. Answer b should read
  {
   CopyFile(“\\farm\rabit_cage\pet.rabit”,                         “\\farm\rabit_cage\rabit.pet”);
  }

Cheers!
0
 

Author Comment

by:rabit
Comment Utility
P.S. my ver of win32 has a flag on it. (Nt)
char fid1[50],fid2[50];
BOOL flag;

CopyFile(fid1,fid2, flag);
where
Use MoveFile() does not.
BUT you got me past my fear of the APIs, Thanks , the compiler can teach the rest! I hope!

0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now