home *** CD-ROM | disk | FTP | other *** search
/ Rat's Nest 1 / ratsnest1.iso / prgmming / c / filemove.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-05  |  2.3 KB  |  89 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <io.h>
  5. #include <share.h>
  6. #include <fcntl.h>
  7. #include <errno.h>
  8. #include <sys\stat.h>
  9.  
  10. #include "C:\IBMCPP\BBSDef.h"
  11.  
  12. unsigned char TestFile(struct FileRecord *File, unsigned char *Path);
  13. unsigned char GetFileNameStartPos(unsigned char *Path);
  14.  
  15. struct FileRecord     File;
  16.  
  17.  
  18. unsigned int main(void)
  19. {
  20.   int OrigFile, DestFile;
  21.   unsigned short Counter=FALSE;
  22.  
  23.   #ifdef __IBMC__
  24.   setvbuf(stdout, NULL, _IONBF, BUFSIZ);
  25.   #endif
  26.  
  27.   if (sizeof(File)!=80) {
  28.      puts("Filerecord size is not 80 bytes!");
  29.      return EXIT_FILEERROR;
  30.   }
  31.  
  32.  
  33.   OrigFile=sopen("FILES.DAT", O_BINARY | O_RDONLY, SH_DENYNONE);
  34.   DestFile=sopen("FILES2.DAT", O_BINARY | O_WRONLY | O_CREAT, SH_DENYNONE, S_IREAD | S_IWRITE);
  35.  
  36.   if (OrigFile==-1 || DestFile==-1) {
  37.     if (OrigFile!=-1) close(OrigFile);
  38.     if (DestFile!=-1) close(DestFile);
  39.     puts("File open error..");
  40.     return EXIT_FILEERROR;
  41.   }
  42.  
  43.     while(read(OrigFile, &File, sizeof(File))==sizeof(File)) {
  44.       if (File.Deleted) continue;
  45.       printf("%u: %s\n", ++Counter, OnlyFileName);
  46.       while (TRUE) {
  47.         if (TestFile(&File, "D:\\PC\\GAMES\\")) break;
  48.         if (TestFile(&File, "D:\\PC\\MISC\\")) break;
  49.         if (TestFile(&File, "D:\\PC\\PROG\\")) break;
  50.         if (TestFile(&File, "D:\\PC\\TELECOM\\")) break;
  51.         if (TestFile(&File, "D:\\PC\\UTILS\\")) break;
  52.  
  53.         if (TestFile(&File, "D:\\TEXT\\GAMES\\")) break;
  54.         if (TestFile(&File, "D:\\TEXT\\GENERAL\\")) break;
  55.         if (TestFile(&File, "D:\\TEXT\\LYRICS\\")) break;
  56.         if (TestFile(&File, "D:\\TEXT\\SEX\\")) break;
  57.         break;
  58.       }
  59.       write(DestFile, &File, sizeof(File));
  60.     }
  61.     close(OrigFile);
  62.     close(DestFile);
  63.     return 0;
  64. }
  65.  
  66. unsigned char TestFile(struct FileRecord *File, unsigned char *Path)
  67. {
  68.   unsigned char Temp[128];
  69.  
  70.   strcpy(Temp, Path);
  71.   strcat(Temp, pOnlyFileName);
  72.   if (access(Temp, FALSE)) return FALSE;
  73.  
  74.   strcpy(File->Name, Temp);
  75.   File->NameStartPos=GetFileNameStartPos(File->Name);
  76.   return TRUE;
  77. }
  78.  
  79. unsigned char GetFileNameStartPos(unsigned char *Path)
  80. {
  81.   unsigned char i=FALSE;
  82.   unsigned char FIND;
  83.   while(*Path) {
  84.     if (*Path=='\\') FIND=i+1;
  85.     ++i; ++Path;
  86.   }
  87.   return FIND;
  88. }
  89.