By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,203 Members | 930 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,203 IT Pros & Developers. It's quick & easy.

Copy Files to a network drive in Win2000

P: n/a
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
Nov 13 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Sat, 6 Sep 2003 14:02:12 -0400, in comp.lang.c , "Nathaniel
Wingard" <Pa******@hotmail.com> wrote:
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.

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>
Nov 13 '05 #2

P: n/a

"Nathaniel Wingard" <Pa******@hotmail.com> wrote in message
news:bj***********@msunews.cl.msu.edu...
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

--
Jeff
Nov 13 '05 #3

P: n/a
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.

"Mark McIntyre" <ma**********@spamcop.net> wrote in message
news:r2********************************@4ax.com...
On Sat, 6 Sep 2003 14:02:12 -0400, in comp.lang.c , "Nathaniel
Wingard" <Pa******@hotmail.com> wrote:
I recently was asked to write a program that moved files to certain placeson 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.

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>

Nov 13 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.