Find the answer to your Linux question:
Results 1 to 3 of 3
i am coding in pure c / solutions can be in c++ too. well this is the problem. i have 3 folders, where it's name are - /dump, /backup and ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Aug 2004
    Posts
    14

    i need urgent help. please. it's on making a log file.


    i am coding in pure c / solutions can be in c++ too.

    well this is the problem. i have 3 folders, where it's name are - /dump, /backup and /process.

    the system has a KORN job. it dumps files (pure flat.text files) into the /dump folder. and the folder will be flooded with the text files.

    [1]then my main problem is.."how to merge those files into a single text file, where it's name is "beforesegmented.txt" and make a copy of itself to another location named /backup. ("beforesegmented.txt" will be transferred to /process folder.)

    i have finish coding on (a) program (which is completely done) will take the "beforesegmented.txt, clear those white spaces and produces a text files, named "out.txt"., (b) inserting those lines to the database.

    i need urgent help please. attached here are the codes of the [1] where i couldntd solve and blurred!


    #include <string.h>
    #include <stdio.h>

    void CopyFileWithoutSpaces( char* in, char* out )
    {
    FILE* fin = fopen( in, "r" );
    FILE* fout = fopen( out, "a" );
    char c;
    char list[2000];
    while( (c = fgetc(fin)) != EOF )
    fscanf(fin, "%s\n",list);
    printf("%s\n",list);
    if ( c != ' ' )
    fputc(c,fout);

    fclose(fin);
    fclose(fout);
    }
    #include <sys/types.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <dirent.h>

    int main ()
    { int argc;
    char *argv[10];
    DIR *dp;
    struct dirent *dirp;
    char in[10];

    if ((dp=opendir("/home/john/dump") ) == NULL )
    {
    printf("Cant open %s", argv[1]);
    }
    while ((dirp = readdir(dp)) != NULL)
    {
    {
    strcpy(in, dirp-> d_name);
    printf("%s\n", dirp-> d_name);
    CopyFileWithoutSpaces( in, "/home/john/dump/out1.txt" );
    }
    }
    close(dp);
    exit(0);
    }

    [/code]

  2. #2
    Just Joined!
    Join Date
    Sep 2004
    Posts
    21
    hi!

    i have seen ur problem but not able to find out the solution..
    but even i want to ask something regarding dirent.h..

    actually my question is ...
    how to find out the size of a directory , directory may contain files and sub folders..so how can i have the total size of that particular directory in 'c' language on LINUX.

    could u pls help me out...

    i want it urgently... :o

    THANX

  3. #3
    Just Joined!
    Join Date
    Aug 2004
    Posts
    14
    timely, it's possible to list out directory. currently i have stopped this project, and continued on new project, but i can give u the source codes. but, if u can find out or alter the codes to more better condition, please do inform me. we might / able to exchange knowledge.

    Code:
    #include <sys/types.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <dirent.h>
    
    int main &#40;&#41;
    &#123;       int argc;
            char *argv&#91;10&#93;;
            DIR             *dp;
            struct dirent   *dirp;
    
    
            if      &#40;&#40;dp=opendir&#40;"/home/john/backup"&#41; &#41; == NULL &#41;/*change to your path or replace with static pointer*/
                    &#123;
                    printf&#40;"Cant open %s", argv&#91;1&#93;&#41;;
                    &#125;
    
    
                    while &#40;&#40;dirp = readdir&#40;dp&#41;&#41; != NULL&#41;
                    &#123;
                            &#123;printf&#40;"%s\n", dirp-> d_name&#41;;
    
    
                            &#125;
                    &#125;
            close&#40;dp&#41;;
            exit&#40;0&#41;;
    &#125;

  4. $spacer_open
    $spacer_close

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •