Solved

copy & renaming files using win32 API

Posted on 1997-09-07
4
1,040 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 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need some help with Microsoft Visual Studio C++ 2003 5 88
Best book to learn C++ 4 97
Safe conversion? 4 88
C++ mouse_event mouse look 7 136
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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 learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

710 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