Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

copy & renaming files using win32 API

Posted on 1997-09-07
4
Medium Priority
?
1,044 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 50 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

963 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