home *** CD-ROM | disk | FTP | other *** search
/ Chip 1999 June / Chip_1999-06_cd.bin / ctenari / Kvarda / source / DIRCONV.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-12  |  3.1 KB  |  113 lines

  1. /************************************************************************\
  2. *
  3. * MODULE    : DIRCONV.C
  4. *
  5. * PROGRAMS  : HTMLENRM, HTMLENAD, CPCONV, UNWIACZ
  6. *
  7. * PURPOSE   : Conversion of files from source directory tree to the     
  8. *             target directory tree and supporting variables and
  9. *             functions
  10. *
  11. \************************************************************************/
  12.  
  13. #include <windows.h>
  14. #include <stdio.h>
  15. #include <string.h>
  16.  
  17. #include "CONV_SUB.H"
  18. #include "EXTMASK.H"
  19.  
  20. /************************************************************************\
  21. * Subdirectory mode
  22. *   SubDirs = TRUE    conversion including subdirectories
  23. *             FALSE   convert only the specified directory
  24. \************************************************************************/
  25.  
  26. static BOOL SubDirs = TRUE;
  27.  
  28. void SetSubdirConversion (BOOL convertsubdirs)
  29. {
  30.    SubDirs=convertsubdirs;
  31. }
  32.  
  33. BOOL IsConvertSubdirMode (void)
  34. {
  35.    return (SubDirs);
  36. }
  37.  
  38. /************************************************************************\
  39. *
  40. * FUNCTION    : ConvertDir
  41. *
  42. * INPUTS      : SourceDir  - source directory
  43. *               TargetDir  - target directory
  44. *
  45. * RETURNS     : None
  46. *
  47. * LOCAL VARS  : FileMask   - source files mask
  48. *               FindData   - source file data
  49. *               SFile      - source file/subdirectory name
  50. *               TFile      - target file/subdirectory name
  51. *               SDir       - source directory (ended by backslash)
  52. *               TDir       - target directory (ended by backslash)
  53. *               hFind      - find files in the directory handle
  54. *
  55. * COMMENTS    : Called recursively
  56. *
  57. \************************************************************************/
  58.  
  59. void ConvertDir( char *SourceDir, char *TargetDir )
  60. {
  61.    WIN32_FIND_DATA FindData;
  62.    char FileMask[256];
  63.    char SFile[256],TFile[256],SDir[256],TDir[256];
  64.    HANDLE hFind;
  65.  
  66.    CreateDirectory(TargetDir,NULL);
  67.    printf("\n Target directory: %s",TargetDir);
  68.  
  69.    strcat(strcpy(FileMask,SourceDir),"\\*");
  70.    hFind=FindFirstFile(FileMask,&FindData);
  71.    if (hFind==INVALID_HANDLE_VALUE)
  72.       return;
  73.  
  74.    strcat(strcpy(SDir,SourceDir),"\\");
  75.    strcat(strcpy(TDir,TargetDir),"\\");
  76. next:
  77.    if (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
  78.      {
  79.       if (!SubDirs)
  80.          goto skip;
  81.       if (FindData.cFileName[0]=='.')
  82.         {
  83.          if (strlen(FindData.cFileName)==1) goto skip;
  84.          if (FindData.cFileName[1]=='.') goto skip;
  85.         }
  86.       strcpy(SFile,SDir);
  87.       strcat(SFile,FindData.cFileName);
  88.       strcpy(TFile,TDir);
  89.       strcat(TFile,FindData.cFileName);
  90.       ConvertDir(SFile, TFile );
  91.      }
  92.    else
  93.      {
  94.       strcpy(SFile,SDir);
  95.       strcat(SFile,FindData.cFileName);
  96.       strcpy(TFile,TDir);
  97.       strcat(TFile,FindData.cFileName);
  98.       if (CheckFilenameExtension(SFile))
  99.          ConvertFile (SFile, TFile);
  100.       else if (stricmp(SFile,TFile)!=0)
  101.         {
  102.          CopyFile(SFile, TFile, FALSE);
  103.          printf("\n     Copied target file: %s", TFile);
  104.         };
  105.      }
  106. skip:
  107.    if (FindNextFile(hFind,&FindData))
  108.       goto next;
  109.    FindClose(hFind);
  110. }
  111.  
  112.  
  113.