Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Win32 API CopyFile does not work

sjors
Beginner
1,902 Views
Hello,

I'm developing a workaround for a colleague that needs to perform a lot of copy statements. "Call System("copy..")" does not work in this case. Therefore I tried to call the win32 API CopyFile using the kernel32 module. It gives the following errormessage:

Error: The same named entity from different modules and/or program units cannot be referenced. [COPYFILE]

The win32 API MoveFile workes fine though. I use compiler 10.1.029.

Here's the samplecode:
[fortran]Program CopyFile

Use Kernel32

Implicit None

Integer(BOOL)      :: retval,NotOverWrite
Character(Len=200) :: lpExistingFileName,lpNewFileName
 
  NotOverwrite = 0

  lpExistingFileName = "D:\TestFile.txt"
  lpNewFileName = "D:\TestFile_copy.txt"

  retval = CopyFile(Trim(lpExistingFileName)//""C,Trim(lpNewFileName)//""C,FALSE)
  retval = MoveFile(lpExistingFileName,lpNewFileName)

End Program CopyFile
[/fortran]
Thanks in advance for any useful answers!

Cheers, Arjen
0 Kudos
3 Replies
GVautier
New Contributor III
1,902 Views
Hello

Your program is named CopyFile so it interfers with the function name.

Change "program CopyFile" to "program Copy_File" and it will work.

0 Kudos
sjors
Beginner
1,902 Views
Auch, that indeed solves the problem. I thought Fortran was more tolerant in the name of the Program itself. Sorry to have bothered you with this, but thanks for the help anyway!

Cheers Arjen
0 Kudos
Steven_L_Intel1
Employee
1,902 Views
In a Fortran program, no two entities in the "global" class may have the same name. These are: program units (main program, subroutines, functions, block data subprograms, modules), common blocks and external procedures.
0 Kudos
Reply