15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Moving files...

Mihir Dalal -- m_dalal@ECE.concordia.CA
Wednesday, December 04, 1996


                   Environment: MSVC 1.52, Windows 95

Hi,

I want to implement the following in one of my menu handlers:
    
    I want to move a database file (.dbf) from a specified directory in 
    my hard drive to my 3.5"  A drive. 

     I tried the following but with no success:
 TRY
  { 
    CFile::Rename("C:/mydir/myfile.dbf", "A:/myfile.dbf"); 
  }
 CATCH( CFileException, e )
  {
    #ifdef _DEBUG
    afxDump << "File " << "c:/mydir/myfile.dbf" << " not found, cause = "
		        << e->m_cause << "\n";
    #endif
   }
  END_CATCH

The documentation of MSVC furthur tells me that CFile::Rename() works 
exactly like the MS-DOS "ren" command. 

An interesting observaton: The "ren" command in MS-DOS does not allow one 
to move a file from one drive to another or from one directory to another.

In contrast, the CFile::Rename() does not allow one to move a file from 
one drive to another BUT it DOES allow moving of a file from one 
directory to another. 

Any reason for this or is it a bug in CFile::Rename() ??

Mihir Dalal
(m_dalal@ece.concordia.ca)



Brad Wilson/Crucial Software -- crucial@pobox.com
Saturday, December 07, 1996

[Mini-digest: 4 responses]

> An interesting observaton: The "ren" command in MS-DOS does not allow one

> to move a file from one drive to another or from one directory to
another.
> 
> In contrast, the CFile::Rename() does not allow one to move a file from 
> one drive to another BUT it DOES allow moving of a file from one 
> directory to another. 
> 
> Any reason for this or is it a bug in CFile::Rename() ??

"Renaming" (moving) a file to anywhere on the same drive is a fixed time
process ... all it has to do it move the directory entry from one directory
to another.  "Renaming" (moving) a file across drives involves a copy and
delete process, and is more involved.

I suspect CFile::Rename() only does the simple process; that allows in
directory renames as well as moves to anywhere on the disk, but not across
disks.  Notice that the MoveFile() API has the same limitation.  Under
Win32, use the MoveFileEx() API to accomplish this.  Under Win 3.1, you can
use the LZCopyFile() API (the file doesn't need to be LZ compressed to be
copied with this function), and then _unlink() the source file.

--
Brad Wilson                       Custom software development & solutions
crucial@pobox.com               Internet and intranet consulting services
The Brads' Consulting          Windows NT/Windows 95 software development
http://www.thebrads.com    Web site planning, development and maintenance
   Content (C) 1996 Brad Wilson; no reproduction without authorization

-----From: Mike Blaszczak 

At 19:17 12/4/96 -0500, Mihir Dalal wrote:

>                   Environment: MSVC 1.52, Windows 95

>In contrast, the CFile::Rename() does not allow one to move a file from 
>one drive to another BUT it DOES allow moving of a file from one 
>directory to another. 

>Any reason for this or is it a bug in CFile::Rename() ??

CFile::Rename() just calls the operating system (via the C runtime libraries)
to get the job done.  There isn't a bug in MFC or in the runtimes; the operating
system doesn't provide a single call to do what you want.

In Win16, the easiest way to solve this problem is to copy the file and delete
the source.  You'll probably want to use _splitpath() to detect when the file is
on a different drive, but that can get tricky if someone's used SUBST or JOIN.

In Win32, there are single calls that move files, even across volumes.
MoveFile()
and MoveFileEx() would do it.

.B ekiM
http://www.nwlink.com/~mikeblas/
I'm afraid I've become some sort of speed freak.
These words are my own. I do not speak on behalf of Microsoft.

-----From: "Peter R. Vermilye" 


----------
From: 	Mihir Dalal[SMTP:m_dalal@ECE.concordia.CA]
Sent: 	Wednesday, December 04, 1996 1:17 PM
To: 	mfc-l@netcom.com
Subject: 	Moving files...


                   Environment: MSVC 1.52, Windows 95

Hi,

I want to implement the following in one of my menu handlers:
   =20
    I want to move a database file (.dbf) from a specified directory in=20
    my hard drive to my 3.5"  A drive.=20

     I tried the following but with no success:
 TRY
  {=20
    CFile::Rename("C:/mydir/myfile.dbf", "A:/myfile.dbf");=20
  }
 CATCH( CFileException, e )
  {
    #ifdef _DEBUG
    afxDump << "File " << "c:/mydir/myfile.dbf" << " not found, cause =
=3D "
		        << e->m_cause << "\n";
    #endif
   }
  END_CATCH

The documentation of MSVC furthur tells me that CFile::Rename() works=20
exactly like the MS-DOS "ren" command.=20

An interesting observaton: The "ren" command in MS-DOS does not allow =
one=20
to move a file from one drive to another or from one directory to =
another.

In contrast, the CFile::Rename() does not allow one to move a file from=20
one drive to another BUT it DOES allow moving of a file from one=20
directory to another.=20

Any reason for this or is it a bug in CFile::Rename() ??

Mihir Dalal
(m_dalal@ece.concordia.ca)


Actually, if I remember my MSDOS INT 21h calls correctly...the rename =
file allows for the moving of a file on a drive but does not allow for =
moving it across drive boundaries...this makes a certain amount of sense =
given that to move a file from one directory to another is just a matter =
of moving the entry from one directory to another and should not involve =
actually "moving" any other data (the information in the file itself).

Hope this is close to accurate and helpful...

Peter R. Vermilye
cpudude@mem.net

PS:  Who does Microsoft call for help?
-----From: mss@tartus.com (Michael Scherotter)

To move files, use API function CopyFile();  

-- 
Michael S. Scherotter            |Architectural Design Tools
Lead Software Developer          |AutoCAD Applications
Tartus Development, Inc.         |Custom CAD Solutions
630 Las Gallinas Ave #300        |__________________________ 
San Rafael, CA 94903                          mss@tartus.com
(415) 491-8925                          michael@charette.com
(415) 491-8921 (fax)               71035.1675@compuserve.com
               http://www.tartus.com/people/mss
____________________________________________________________




| Вернуться в корень Архива |