Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

copy & renaming files using win32 API

Posted on 1997-09-07
4
Medium Priority
?
1,043 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
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 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 learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses

688 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