ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Zero Byte File Identification

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Zero Byte File Identification

    Does anyone have any homegrown solutions for identifying a ZERO byte DOS file?

    I'm trying to keep from FTP'ing ZERO byte files up to my ISeries for processing since CPYFRMPCD seems to puke on them.

  • #2
    Re: Zero Byte File Identification

    What's doing the FTP'ing ? Are you using a .cmd file or a programme or something ? (I'm after the language you want to do it in).

    Comment


    • #3
      Re: Zero Byte File Identification

      Do a IFS directory read and get the file size. Search code400 for IFS directory read program.
      Good Luck
      Bill
      "A good friend will bail you out of jail,
      A true friend would be sitting beside you saying,
      'Wow, that was fun.'"

      Comment


      • #4
        Re: Zero Byte File Identification

        Here's a bit of Windoze C code I threw together that will print out the file size of a given file and optionally delete it.

        Code:
        #include <windows.h>
        #include <stdio.h>
        #include <sys/types.h>
        #include <sys/stat.h>
        
        void ShowHelp()
        {
           printf("filesize.exe {filename} {/d}                                     \n");
           printf("             {/h>                                                \n");
           printf("                                                                 \n");
           printf("Displays the size of the file and optionally deletes empty files \n");
           printf("                                                                 \n");
           printf("  /h - Displays this message                                     \n");
           printf("  /d - Deletes the file if its size is zero                      \n");
        }
        
        int main( int argc, char *argv[])
        {
           if(argc<2)
           {
              ShowHelp();
              return 0;
           }
           if(!stricmp(argv[1],"/h"))
           {
              ShowHelp();
           }
        
           {
              FILE *f = fopen(argv[1],"r");
              if(f==NULL)
              {
                 printf("File not found\n");
              }
              else
              {
                 fclose(f);
                 {
                    struct _stat s;
        
                    if(0!=_stat(argv[1],&s))
                    {
                       printf("Failed to get file attributes\n");
                       return 0;
                    }
                    printf("%i",s.st_size);
                    if(argc==3)
                    {
                       if( !stricmp(argv[2],"/d") && s.st_size==0)
                       {
                          DeleteFile(argv[1]);
                          printf(" - File deleted\n");
                       }
                    }
                 }
              }
        Example...

        Code:
        C:\Documents and Settings\Andy>dir test.txt
         Volume in drive C has no label.
         Volume Serial Number is 409B-65EE
        
         Directory of C:\Documents and Settings\Andy
        
        02/06/2007  01:44                 0 test.txt
                       1 File(s)              0 bytes
                       0 Dir(s)  15,028,170,752 bytes free
        
        C:\Documents and Settings\Andy>filesize test.txt /d
        0 - File deleted
        
        C:\Documents and Settings\Andy>

        Comment


        • #5
          Re: Zero Byte File Identification

          Thanks for sharing Andy
          All my answers were extracted from the "Big Dummy's Guide to the As400"
          and I take no responsibility for any of them.

          www.code400.com

          Comment


          • #6
            Re: Zero Byte File Identification

            *I wipe away a happy tear at the site of C*

            Yey for Andy!
            Your future President
            Bryce

            ---------------------------------------------
            http://www.bravobryce.com

            Comment

            Working...
            X