Solved

copy & renaming files using win32 API

Posted on 1997-09-07
4
1,035 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
ID: 1169077
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
ID: 1169078
Thanks, I'll get the hang of NT sooner or later!
0
 
LVL 1

Expert Comment

by:ohell
ID: 1169079
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
ID: 1169080
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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

770 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