Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Programming job for someone

  • 22-04-2004 11:22PM
    #1
    Closed Accounts Posts: 2,027 ✭✭✭


    Hi all, I need someone to write a program which when run, scans a specific directory on my PC and takes each file found in the director and dumps it to a comma delimited text file.

    The source files are all exactly the same (10 lines of text). So basically I want to go from this

    Source File content

    Line1:Hello there
    Line2:Are you well
    Line3:123456

    etc etc.

    to a single line in the comma delimited text file - e.g.

    Hello there,are you well,123456

    I need the program to run unders Windows Xp , Windows 2000.

    If anyone can help out I'd appreciate and we can negotiate a payment.


Comments

  • Registered Users, Registered Users 2 Posts: 1,372 ✭✭✭silverside


    I'll do it at the weekend. Shouldnt take too long. Let me know if that is what you want.

    How do you want the folder to be selected (at the command line?)

    e.g. so I type 'Doit c:\mydir c:\newfile.txt' and it puts all the files in mydir together into newfile.txt, in the format you specified?

    I'll work on that basis, or post a detailed spec if you want.

    You can buy me a pint sometime or something.

    It would help if you could zip up some sample input & output files, for testing purposes.


  • Closed Accounts Posts: 2,027 ✭✭✭alleepally


    Thats great silverside. I'll pm you to get your email address to send the sample files to.


  • Banned (with Prison Access) Posts: 13,018 ✭✭✭✭jank


    how are you going to write it silverside (C is suppose??)

    just curious


  • Registered Users, Registered Users 2 Posts: 1,372 ✭✭✭silverside


    I was going to use C++ with stl,cout etc but I just realised I dont know how to read a folder contents in C.

    I guess i will use Visual C++ and the win32 API FindFirstFile, etc as that is what I know best. It might be a bit clunky but it will work & be written quickly.

    Having said that Java or Perl would probably be better for this, but 'Stick to the knitting' so C++ it is, will wrap up into a nice standalone .exe as well.


  • Registered Users, Registered Users 2 Posts: 3,890 ✭✭✭cgarvey


    *cough* PERL (on windows you can use ActivePerl from www.ActiveState.com) .. (PM me with email addy if you want .exe version of it ~600K)

    (Perl) Sample usage: blah.pl c:\dir c:\results.txt
    #!perl
    
    if( $#ARGV == 1 ) {
    	if( -d( $ARGV[0] ) ) {
    		if( !-f( $ARGV[1] ) ) {
    			opendir( DIR, $ARGV[0] );
    			my( @dirListing ) = readdir( DIR );
    			closedir( DIR );
    	
    			open( RESULTS, ">>" . $ARGV[1] );
    			foreach( @dirListing ) {
    				if( -f( $ARGV[0] . "\\" . $_ ) && $_ ne "." && $_ ne ".." ) {
    					my( $line ) = "";
    					my( $haveWritten ) = 0;
    					open( F, $ARGV[0] . "\\" . $_ );
    					while( defined( $line = <F> ) ) {
    						$line =~ s/[\r\n]//g;
    						if( $haveWritten ) { print RESULTS ","; }
    						print RESULTS $line;
    						$haveWritten = 1;
    					}
    					print RESULTS "\n";
    				}
    			}
    			close( RESULTS );
    		}
    		else {
    			print "Output file already exists.\n";
    			&printUsage();
    		}
    	}
    	else {
    		print "Directory does not exist\n";
    		&printUsage();
    	}
    }
    else {
    	print "Insufficient args\n";
    	&printUsage();
    }
    
    exit( 0 );
    
    sub printUsage {
    	print "Sample usage: $! c:\\dir c:\\results.txt\n\n";
    }
    


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 1,372 ✭✭✭silverside


    Perl looks good but I never bothered to learn it.

    cgarvey do you want to take over as it seems a lot simpler doing it that way than writing a C++ app (sledgehammer/nut) ; once that is tested that looks like it would do the job, except i dont want to learn Perl just yet to check your code

    :)


  • Registered Users, Registered Users 2 Posts: 3,890 ✭✭✭cgarvey


    Originally posted by KlodaX
    I bet ya a tener that the previous post is useless to him

    Because of the "Line1:" ?
    Because its PERL?


  • Registered Users, Registered Users 2 Posts: 3,890 ✭✭✭cgarvey


    Originally posted by silverside
    Perl looks good but I never bothered to learn it.

    cgarvey do you want to take over as it seems a lot simpler doing it that way than writing a C++ app (sledgehammer/nut) ; once that is tested that looks like it would do the job, except i dont want to learn Perl just yet to check your code

    :)

    Well its probably easier in PERL, but PERL exe's are quite big (~650KB for this one)... I've left an exe of the PERL source above which can be run straight from the command line (no PERL required) here if you trust me.. any small mods I can do.. I did only mean to show it could be done!.

    .cg


  • Registered Users, Registered Users 2 Posts: 1,372 ✭✭✭silverside


    cheers, i'll do it in Win32 C++ myself, not that i don't trust you or anything but half the time its easier to write code oneself than to read someone elses'.


  • Closed Accounts Posts: 437 ✭✭casper-


    I'm curious what the original poster thinks about the PERL exe --- I can't see why exe size would even come into the discussion if the app works as requested. It is true, C is just not very well suited to some tasks, and as much as I'm a hard-core C/C++ guy, I can respect that sometimes VB or Perl or whatever is better suited to the task at hand.

    Provided that PERL code works, I don't think silverside should even bother taking time out of his weekend to hammer our a C/C++ version .... unless you just want some programming practise :)

    just my €0.02...


  • Advertisement
  • Closed Accounts Posts: 2,027 ✭✭✭alleepally


    Mr Garvey, you are a star! Your code works great!!!

    Thanks a million.


  • Registered Users, Registered Users 2 Posts: 3,890 ✭✭✭cgarvey


    Originally posted by alleepally
    Mr Garvey, you are a star! Your code works great!!!

    Thanks a million.

    No problem, things like that are easy in PERL, so no major effort on my part, glad it worked.


    Originally posted by KlodaX
    I bet ya a tener that the previous post is useless to him

    KlodaX, I take it (as seen as your post is deleted) that the bet is off ;)


  • Registered Users, Registered Users 2 Posts: 629 ✭✭✭str8_away


    Created in VB6

    20k in size (please change .jpg to .exe)
    http://members.boards.ie/str8_away/DirPrint.jpg

    let me know what you guys think
    :D


  • Registered Users, Registered Users 2 Posts: 3,890 ✭✭✭cgarvey


    Originally posted by str8_away
    20k in size

    yes, but that doesn't include runtimes required ;) (I'm being pedantic now, sorry!)


  • Closed Accounts Posts: 437 ✭✭casper-


    Originally posted by cgarvey
    KlodaX, I take it (as seen as your post is deleted) that the bet is off ;)

    Damn ... I wanted in on that action too :)

    Nice job cgarvey ... always cool to see someone demonstrate where C/C++/VB/Delphi aren't the best solution -- helps to ground us other coders :)


  • Registered Users, Registered Users 2 Posts: 629 ✭✭✭str8_away


    Originally posted by cgarvey
    yes, but that doesn't include runtimes required ;) (I'm being pedantic now, sorry!)

    Not to worry, it is a good point.
    for win9x you would need vb runtime
    but VB run time are part of win2k and winxp
    See first post
    Originally posted by alleepally
    I need the program to run unders Windows Xp , Windows 2000.


  • Registered Users, Registered Users 2 Posts: 3,890 ✭✭✭cgarvey


    Originally posted by str8_away
    See first post

    lol, now you're being pedantic .. serves me right!


  • Registered Users, Registered Users 2 Posts: 1,372 ✭✭✭silverside


    Yeah, that Perl looks realy handy, no need for me to do anything now :)

    Must try to learn it sometime - I suppose there is an O'Reilly book out there which covers it.


  • Registered Users, Registered Users 2 Posts: 32,451 ✭✭✭✭watty


    Originally posted by alleepally
    Hi all, I need someone to write a program which when run, scans a specific directory on my PC and takes each file found in the director and dumps it to a comma delimited text file.

    The source files are all exactly the same (10 lines of text). So basically I want to go from this

    Source File content

    Line1:Hello there
    Line2:Are you well
    Line3:123456

    etc etc.

    to a single line in the comma delimited text file - e.g.

    Hello there,are you well,123456

    I need the program to run unders Windows Xp , Windows 2000.

    If anyone can help out I'd appreciate and we can negotiate a payment.

    Fairly trivial and can easily be done in VB, C, C++ ,C#, Modula-2, Perl, wsh, Pascal etc.

    With such a trivial application, experience and familiary with Windows File /Directory APIs or Libraries and using the language your are most familar with will work best.

    Modula-2 will give the smallest .exe that needs no runtime.

    VB needs the biggest runtime, but is fastest to implement if you are familar with such a task.

    Perl and WSH may be slow. VB Script/ WSH needs the Windows Script Host runtime.

    Java is possible too, but no significant advantage over C++ or C#

    Perl, Java, C family are harder to maintain later, especially if you arn't writing the same kind of stuff every day.


    I cheat. I do GUI stuff mostly in VB and sometimes as HTML. Then when VB doesn't cut it if a VERY windows APIish thing is needed make a DLL in C++ (migrating to C# now). If the DLL doesn't do much with Windows APIs then I use Modula-2.

    It is trivial enough to use a DLL in VB written in any arbitary language. Just remember to intialise any strings in VB to any content at least as long as the C/Modula2/Pascal procedure expects to fill, as VB strings are dynamic and otherwise you are passing a pointer to a zero length array. Seems to be only pitfall in VB /Other interfacing.


Advertisement