For Programmers: Free Programming Magazines  


Home > Archive > Fortran > March 2007 > copy and move files









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author copy and move files
Fluid

2007-03-29, 8:10 am

Hi, i need help.i am a quite new user of fortran. I would like to
rename a file (used as input file) and move it to another directory.
Which command can I use?
thanks

Gib Bogle

2007-03-29, 8:10 am

Fluid wrote:
> Hi, i need help.i am a quite new user of fortran. I would like to
> rename a file (used as input file) and move it to another directory.
> Which command can I use?
> thanks
>


If you tell us the compiler you're using, someone will be able to
explain how to invoke system commands.
Arjen Markus

2007-03-29, 8:10 am

On 29 mrt, 12:03, "Fluid" <bernardini.chi...@gmail.com> wrote:
> Hi, i need help.i am a quite new user of fortran. I would like to
> rename a file (used as input file) and move it to another directory.
> Which command can I use?
> thanks


Fortran is not really suited for this type of tasks.
What you can do is one of the following:

1. Use the "system" subroutine. It is a common extension to
the standard. You can use it to run system commands:

character*100 command
write( command, '(4a)' ) 'copy ', file1, ' ', file2
call system(command)

This is a system-dependent and compiler-dependent way
of doing it though.

2. Open the old file and the new one, read the information
from the old file and write it to the new one.

This is an inefficient process, and depending on the
details (type of file, whether you want an exact copy
or can live with trailing blanks and the like) you may
be able to get what you want.

There was another thread not too long ago about the same
subject (or it ended up discussing the various options).
That will provide more details.

Regards,

Arjen

Beliavsky

2007-03-29, 8:10 am

On Mar 29, 7:19 am, "Arjen Markus" <arjen.mar...@wldelft.nl> wrote:
> On 29 mrt, 12:03, "Fluid" <bernardini.chi...@gmail.com> wrote:
>
>
> Fortran is not really suited for this type of tasks.
> What you can do is one of the following:
>
> 1. Use the "system" subroutine. It is a common extension to
> the standard. You can use it to run system commands:
>
> character*100 command
> write( command, '(4a)' ) 'copy ', file1, ' ', file2
> call system(command)


call system("copy " // trim(file1) // " " // trim(file2))

is more concise and more general, since it will work even if the file
names are long

Arjen Markus

2007-03-29, 7:07 pm

On 29 mrt, 15:08, "Beliavsky" <beliav...@aol.com> wrote:
> On Mar 29, 7:19 am, "Arjen Markus" <arjen.mar...@wldelft.nl> wrote:
>
>
>
>
>
>
>
>
>
>
> call system("copy " // trim(file1) // " " // trim(file2))
>
> is more concise and more general, since it will work even if the file
> names are long- Tekst uit oorspronkelijk bericht niet weergeven -
>
> - Tekst uit oorspronkelijk bericht weergeven -


Oops, you are right - you might even add '"' around the file names
to get it absolutely (?) foolproof.

Regards,

Arjen

Walter Spector

2007-03-29, 7:07 pm

Fluid wrote:
>
> Hi, i need help.i am a quite new user of fortran. I would like to
> rename a file (used as input file) and move it to another directory.
> Which command can I use?
> thanks


If you are using a compiler which supports POSIX libraries, such as
the Intel compiler, it is trivial. First call PXFLINK to create a new
link to the data, then PXFUNLINK to remove the old link to the data:

character(100) :: oldfn, newfn
:
call PXFLINK (oldfn, len_trim (oldfn), newfn, len_trim (newfn), ierr)
if (ierr /= 0) some error occurred...

call PXFUNLINK (oldfn, len_trim (oldfn), ierr)
if (ierr /= 0) some error occurred...
:

W.
Fluid

2007-03-29, 7:07 pm

On 29 Mar, 13:24, Gib Bogle <b...@ihug.too.much.spam.co.nz> wrote:
> Fluid wrote:
>
> If you tell us the compiler you're using, someone will be able to
> explain how to invoke system commands.



I'm working on PC, using Compaq visual fortran.

dpb

2007-03-29, 7:07 pm

On Mar 29, 8:31 am, "Fluid" <bernardini.chi...@gmail.com> wrote:
> On 29 Mar, 13:24, Gib Bogle <b...@ihug.too.much.spam.co.nz> wrote:
>
>
>
> I'm working on PC, using Compaq visual fortran.


CVF uses "SYSTEM" to send a command to the OS shell. Alternatively,
there are the necessary interfaces and data structures to the
underlying Win32 API routines CopyFile or MoveFile defined in the
KERNEL32 module supplied as one other alternative. Of course, this is
also compiler- and OS-specific so the ususal caveats apply...

Fluid

2007-03-29, 7:07 pm

On 29 Mar, 16:14, "dpb" <dpboza...@swko.net> wrote:
> On Mar 29, 8:31 am, "Fluid" <bernardini.chi...@gmail.com> wrote:
>
>
>
>
>
> CVF uses "SYSTEM" to send a command to the OS shell. Alternatively,
> there are the necessary interfaces and data structures to the
> underlying Win32 API routines CopyFile or MoveFile defined in the
> KERNEL32 module supplied as one other alternative. Of course, this is
> also compiler- and OS-specific so the ususal caveats apply...


thank you all. i'll try.

dpb

2007-03-29, 7:07 pm

On Mar 29, 9:33 am, "Fluid" <bernardini.chi...@gmail.com> wrote:
> On 29 Mar, 16:14, "dpb" <dpboza...@swko.net> wrote:
>
>
>
>
>
>
>
>
>
>
>
> thank you all. i'll try.- Hide quoted text -


Oh, and lest I forget, there's also the RENAME() and RENAMEFILEQQ()
routines in the DFPORT and DFLIB modules that are wrappers to the APIs
already prepared. For some reason they didn't provide higher level
wrappers for copy or move. RENAME, of course, on Win32 fails across
different media so that is a restriction as opposed to others but is
potentially much quicker if files are large in avoiding an actual
physical copy operation.

Charles Russell

2007-03-31, 7:03 pm

Fluid wrote:
> Hi, i need help.i am a quite new user of fortran. I would like to
> rename a file (used as input file) and move it to another directory.
> Which command can I use?
> thanks
>

If you are indeed a *user* rather than a *programmer*, you may find it
simpler to separate the math from the housekeeping, and call both your
fortran code and the system utilities from a makefile, a shell script,
or one of the many scripting languages.
Charles Russell

2007-03-31, 7:04 pm

Charles Russell wrote:
> Fluid wrote:
>
> If you are indeed a *user* rather than a *programmer*, you may find it
> simpler to separate the math from the housekeeping, and call both your
> fortran code and the system utilities from a makefile, a shell script,
> or one of the many scripting languages.


Perhaps this was too terse for a novice, so I'll elaborate. Fortran is
easy if you stick to math, but otherwise things can get quite
complicated. So for simplicity do the math in fortran, try to find some
simple high-level tool for anything else, and glue everything together
in a script. I usually do this with an extra target or two in the same
makefile that builds the fortran executable. Learning to use makefiles
(and to build libraries) is worth the hassle even for an occasion/casual
*user*.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com