![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Newbie
Join Date: Feb 2008
Posts: 15
Rep Power: 0
![]() |
File comparison program
The end of my first school year as a programmer is closing in.We heave learned the basic things of C++ programming.I have been doing quite good in programming so far and i passed my exam with 9 grade(9/10).But the real chalenge for me came today.I have accepted to write a program which will help me pass the 2nd exam.I am not quite sure if i can do it all alone,but it's ok since i am allowed to use all the sources avaliable to me.So far this community has been really helpfull for me and i hope it will stay that way.
The assistant of my programming professor came with a smart idea that i should make a program that will compare files in 1 folder and all of it's subfolders.It should compare their names,their size,if they are hidden and system files.And if these conditions are true it should print the names of those files and their locations. I want you to know that my primary objective is to learn how to program and i,by any means don't want anyone to write this thing for me,i only need some kind of starting tips and pointers and some usefull thing that will help me writing my program. Thanks in advance. |
|
|
|
|
|
#2 |
|
PFO God In Training
![]() Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 544
Rep Power: 4
![]() |
Re: File comparison program
You need to call a system function to get a list of all the files in a folder. Then use recurson to process all its subfolders, and subfolders of the subfolders.
_findfirst() and _findnext() are useful functions to do that. google for those functions and you will find lots of examples. Here is just one of many.
__________________
True Terror is to wake up one morning and discover that your high school class is running the country - Kurt Vonnegut Jr. |
|
|
|
|
|
#3 |
|
Expert Bug Developer
Join Date: Apr 2008
Posts: 21
Rep Power: 0
![]() |
Re: File comparison program
Which operating system do you intend to write this program for?
|
|
|
|
|
|
#4 | |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,222
Rep Power: 5
![]() |
Re: File comparison program
Quote:
Second, I consider that the value in your exercise is learning to practically cope with the need to use C++ with functions/data structures/ etc that go outside scope of the C++ standard. I suggest you consider ways to structure your program to aid portability (eg have a set of functions that your code calls, which calls the right functions depending on operating system). This will be useful in terms of learning how to DETECT what operating system your code is on (eg compiler/OS specific macros), writing a program so it will compiler and then execute despite calling different functions, and use of build techniques (eg makefiles) to help with that. Keep in mind that it is usually a good idea to ensure the bulk of your code is portable (ie standard C++), so the trick is to minimise effort to achieve that. If you have more than one call of functions like findfirst() and findnext() in your code, it is not portable -- consider how you would address the problem of getting the result of functions like findfirst() to your code, without calling findfirst() on multiple places in your code because, if you call it multiple times, you need to modify that code every time you change operating system. Actually try (i.e. have it as a specific goal) to produce a code base that will work on two different operating systems. Such as windows and a unix variant. You will encounter various portability issues, but addressing those issues will be a useful practical learning exercise for you.
__________________
Dear God So far today I've done all right. I haven't been grumpy yet. But in a few minutes, God, I'm going to get out of bed, and from then on I'm going to need a lot more help. AMEN |
|
|
|
|
|
|
#5 |
|
Newbie
Join Date: Feb 2008
Posts: 15
Rep Power: 0
![]() |
Re: File comparison program
Thanks a lot,just for information i intend on making a program for windows,but just as grumpy suggested i may try to make it useable on more operating systems.
|
|
|
|
|
|
#6 |
|
Newbie
Join Date: Feb 2008
Posts: 15
Rep Power: 0
![]() |
Re: File comparison program
Ok, i did a research for those functions and i also found out what recursion is.But maybe i am a bit thick or i can't think straight these days because i can't find out how to use these functions properly.
When i try to use the function on some already declared string that contains the path of the file name,it makes some problems like:"Cannot convert constant char to char" |
|
|
|
|
|
#7 |
|
PFO God In Training
![]() Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 544
Rep Power: 4
![]() |
Re: File comparison program
Please post your code so that someone can help you.
__________________
True Terror is to wake up one morning and discover that your high school class is running the country - Kurt Vonnegut Jr. |
|
|
|
|
|
#8 |
|
Newbie
Join Date: Feb 2008
Posts: 15
Rep Power: 0
![]() |
Re: File comparison program
Ok this is a simple code that i made just to test this function
<c++> Syntax (Toggle Plain Text)
|
|
|
|
|
|
#9 | ||
|
PFO God In Training
![]() Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 544
Rep Power: 4
![]() |
Re: File comparison program
Quote:
Had you read this you would have found that Quote:
you need to add * for the search criteria. Just the beginning directory won't work path="C:\\*.*"
__________________
True Terror is to wake up one morning and discover that your high school class is running the country - Kurt Vonnegut Jr. |
||
|
|
|
|
|
#10 |
|
Newbie
Join Date: Feb 2008
Posts: 15
Rep Power: 0
![]() |
Re: File comparison program
Ok thanks for supporting me and helping me so far.I have used google and menaged to write something on my own using some already made programs.I came up with this code:
<c++> Syntax (Toggle Plain Text)
It does...something,it lists only files in the folder you select.But i still seem to be far from my objective. P.S. I am a C++ "programer"(lol),so i use cout always,i copied the printf commands from another code and i tried replacing them with the cout command,but it prints out sucessfully only cfile.attrib and i don't understand the rest .And sorry if i am being annoying. Last edited by Marijan; May 20th, 2008 at 3:09 PM. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Raw C++ File Transfer Program with GUI | c0ldshadow | C++ | 2 | Aug 7th, 2006 5:04 AM |
| How to start a program upon file creation ? | Marc_piecko | C | 4 | May 22nd, 2006 3:52 AM |
| Basic File Search Program | Twilight | C++ | 4 | May 18th, 2006 3:36 PM |
| checking file existing time to time, in the same time program do other operation | myName | C++ | 3 | Mar 13th, 2006 8:39 PM |
| airport Log program using 3D linked List : problem reading from file | gemini_shooter | C++ | 0 | Mar 2nd, 2005 4:12 PM |