Copy Files to a network drive in Win2000

  • Thread starter Nathaniel Wingard
  • Start date
N

Nathaniel Wingard

I recently was asked to write a program that moved files to certain places
on a network drive based on what the files were (mainly filenames since the
files are mostly Office documents of various types). I have tried rename()
but it seems to have problems with moving things across file systems, and I
have had problems with system("cmd.exe /c move file1.doc file2.doc") and
various like comands with it not moving all the files all the time (I'm not
sure why it does it sometimes and not others). I don't want to have to move
the file by copying it bit by bit to another file and deleting the original,
though I fear that will be the only way to do it. If there are any serious
inconsistancies it is because I couldn't find the code in the few seconds
before typing this, and I am running from memory. Thanks in advance.
Nathaniel
 
M

Mark McIntyre

I recently was asked to write a program that moved files to certain places
on a network drive based on what the files were

There's no sensible portable way to do this in C. As you found out,
rename() may or may not do it, its implementation specific.

One portable way would be to open each file in binary mode, copy its
contents to a new file at the new location, then remove() the old one.
This is likely to be pretty inefficient but would work.

However its very likely your OS provides more sensible ways to do this
- for instance a cursory glance at the Win32 API suggests
MoveFileEx(). By the way it took me about 30 seconds to find this, and
I strongly recommend searching your local documentaiton before going
to usenet, its usually quicker for trivial questions. :)

Also, C is not really the best language for it TBH. Perl might be
better. Learn perl, its worth it.
 
J

Jeff

Nathaniel Wingard said:
I recently was asked to write a program that moved files to certain places
on a network drive based on what the files were (mainly filenames since the
files are mostly Office documents of various types). I have tried rename()
but it seems to have problems with moving things across file systems, and I
have had problems with system("cmd.exe /c move file1.doc file2.doc") and
various like comands with it not moving all the files all the time (I'm not
sure why it does it sometimes and not others). I don't want to have to move
the file by copying it bit by bit to another file and deleting the original,
though I fear that will be the only way to do it. If there are any serious
inconsistancies it is because I couldn't find the code in the few seconds
before typing this, and I am running from memory. Thanks in advance.
Nathaniel

Try comp.os.ms-windows.programmer.win32
 
N

Nathaniel Wingard

Unfortunately I did look in my references, wich after knowing the name of
the function took me a few minutes to find (I really don't know how this is
organized), but it looks as if that function should do what I want it to,
thanks. As for Perl, I thought about it, but IIRC it is an interpreted
language and I really don't want to put a perl interpreter on all the
machines so that I can run it. Maybe some other day.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top