home *** CD-ROM | disk | FTP | other *** search
- /************************************************************************\
- *
- * MODULE : DIRCONV.C
- *
- * PROGRAMS : HTMLENRM, HTMLENAD, CPCONV, UNWIACZ
- *
- * PURPOSE : Conversion of files from source directory tree to the
- * target directory tree and supporting variables and
- * functions
- *
- \************************************************************************/
-
- #include <windows.h>
- #include <stdio.h>
- #include <string.h>
-
- #include "CONV_SUB.H"
- #include "EXTMASK.H"
-
- /************************************************************************\
- * Subdirectory mode
- * SubDirs = TRUE conversion including subdirectories
- * FALSE convert only the specified directory
- \************************************************************************/
-
- static BOOL SubDirs = TRUE;
-
- void SetSubdirConversion (BOOL convertsubdirs)
- {
- SubDirs=convertsubdirs;
- }
-
- BOOL IsConvertSubdirMode (void)
- {
- return (SubDirs);
- }
-
- /************************************************************************\
- *
- * FUNCTION : ConvertDir
- *
- * INPUTS : SourceDir - source directory
- * TargetDir - target directory
- *
- * RETURNS : None
- *
- * LOCAL VARS : FileMask - source files mask
- * FindData - source file data
- * SFile - source file/subdirectory name
- * TFile - target file/subdirectory name
- * SDir - source directory (ended by backslash)
- * TDir - target directory (ended by backslash)
- * hFind - find files in the directory handle
- *
- * COMMENTS : Called recursively
- *
- \************************************************************************/
-
- void ConvertDir( char *SourceDir, char *TargetDir )
- {
- WIN32_FIND_DATA FindData;
- char FileMask[256];
- char SFile[256],TFile[256],SDir[256],TDir[256];
- HANDLE hFind;
-
- CreateDirectory(TargetDir,NULL);
- printf("\n Target directory: %s",TargetDir);
-
- strcat(strcpy(FileMask,SourceDir),"\\*");
- hFind=FindFirstFile(FileMask,&FindData);
- if (hFind==INVALID_HANDLE_VALUE)
- return;
-
- strcat(strcpy(SDir,SourceDir),"\\");
- strcat(strcpy(TDir,TargetDir),"\\");
- next:
- if (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
- {
- if (!SubDirs)
- goto skip;
- if (FindData.cFileName[0]=='.')
- {
- if (strlen(FindData.cFileName)==1) goto skip;
- if (FindData.cFileName[1]=='.') goto skip;
- }
- strcpy(SFile,SDir);
- strcat(SFile,FindData.cFileName);
- strcpy(TFile,TDir);
- strcat(TFile,FindData.cFileName);
- ConvertDir(SFile, TFile );
- }
- else
- {
- strcpy(SFile,SDir);
- strcat(SFile,FindData.cFileName);
- strcpy(TFile,TDir);
- strcat(TFile,FindData.cFileName);
- if (CheckFilenameExtension(SFile))
- ConvertFile (SFile, TFile);
- else if (stricmp(SFile,TFile)!=0)
- {
- CopyFile(SFile, TFile, FALSE);
- printf("\n Copied target file: %s", TFile);
- };
- }
- skip:
- if (FindNextFile(hFind,&FindData))
- goto next;
- FindClose(hFind);
- }
-
-
-