![]() |
|
#1
|
|||
|
|||
C++ for moving files across network?Hi. First post here, I wanted to run an idea by you guys and ask if you think C++ is a good way to do it or not. I am a fairly novice C++ programmer, but I learn quickly. I do not have on hand a C++ book of any kind, nor do I have much professional coding experience. I am still in college but on a coop job in an IT department where I have been asked to make this program.
My tools are Windows XP, Microsoft Visual Studio .NET 2003 (or whatever free compiler I can get on the internet I guess). The machines this is being done on: All Dell, Intel based machines, all fairly recent. The oldest are early Pentium 4 systems. All OS's are Windows 2000 or XP. The main purpose of this program is to: Ask the user for their name and ID # for the purpose of storing their files in a unique folder based on their name Find a specified folder on their C:\ directory (first level on C:\), and if there both possible folder names, to find the one with the latest date To mount a shared folder on another computer on our network See if they already have a folder based on their name on the shared folder, and if it is already there, delete it, then copy the whole folder found on the C:\ into a folder based on their name and ID # Automatically unmount the drive so that the user has no access to it outside while this program is running. I'd like minimal cryptic errors from DOS commands. When I run system() calls, it displays the output from these commands like you'd usually see in DOS, and I'd like to suppress that if possible. I'm also trying to keep as much out of the user's hands as I can. All they should see on their screen after they input their name: Moving files...files moved, thank you come again. I've already got a working code to do absolutely everything I need. The question is can I improve this code in terms of style, using safer functions for sake of being compliant or to avoid things like memory leaks. I'm going to post sections of my code because it currently is 349 lines uncommented (will add comments for your understanding). How I did the program: The naming thing is simple, I just cout a request for the name or ID, and use getline( cin, string, '\n' ) to grab the whole line in case their first or last name has a space in it (Mary Anne, etc.) Next is where I really have my issues on if I can improve my current code or should try using something else. I use a lot of system calls from here on out. See this section of code: CPP / C++ / C Code:
This code above just tells me if there's either or folder above. I use the value of counts to:end the program when there is neither folder where they should be located; move the proper folder; figure out which folder has the latest modified date and move only that one. Things I'd like you guys to comment on: Is there an easier way to do that nested for loop with if statement? For the system call I have: system( "dir C:\\ /ad /b /l > directory.txt" ); Is there any other ways of doing that? Is there any way to search only in C:\ for folders besides the way I've done it with the DOS "dir" command? The one I'm not sure I like at all is a function I made that moves the folder over. CPP / C++ / C Code:
Here are a boat load of system() calls. Honestly, they make me nervous. I read why using system("pause") is a bad idea on the gidnetworks site, so I don't know if I should try avoiding such calls for what I'm doing. Also, are there any risks in moving files that might be as big as 2GB with this command? Are there smarter ways of doing this? Do I even want to be doing this in C++ or am I better off doing it some other way? Tear me apart, let me know. Thanks in advance! -Dave Last edited by LuciWiz : 25-May-2006 at 14:44.
Reason: Please insert your C++ code between [c++] & [/c++] tags
|
|
#2
|
||||
|
||||
Re: C++ for moving files across network?Quote:
Quote:
First, for memory leaks as long as you are not allocating dynamic memory you should be fine. As for system() calls, get rid of them. There are functions in Standard C++ that can handle some of the system calls directly, like deleting files (remove()). Quote:
Same with mounting, although I believe you will be looking at the Windows API's -- another type of function to access the Operating System. Quote:
In one sense, with system() you are in less control of the program. In essense you are contracting out a portion of your project to a consulting company rather than keeping the project in-house. The program you call will utilize the same resourses you'd use to write the program yourself, but you have to figure out how to do that. They already know -- that's why you farmed out the task. I personally feel calling system() should be limited at worst, never used at best. But if you don't have the development time, it does the job. __________________
Age is unimportant -- except in cheese |
Recent GIDBlog
Meeting the local Iraqis by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| issues compiling .h and .cpp files with Dev C++ | iceman2006 | C++ Forum | 9 | 17-May-2006 19:32 |
| Bloodshed Dev C++ Project Options | JdS | C++ Forum | 6 | 11-Nov-2005 17:23 |
| Checking source codes of image, audio and video files | onauc | C Programming Language | 5 | 26-Feb-2005 21:47 |
| Apache2 config issues | monev | Apache Web Server Forum | 2 | 28-Jun-2004 06:19 |
| Can't view pages from another machine on the Intranet | aevans | Apache Web Server Forum | 9 | 14-May-2004 02:26 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The