How  do I copy files using a wild card for example ODFL214*.* to a specific folder in C

1030071002
1030071002 used Ask the Experts™
on
How  do I copy files using a wild card for example ODFL214*.* to a specific folder in C
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2012
Commented:
If that is for Windows, 'SHFileOperation()' (http://msdn.microsoft.com/en-us/library/windows/desktop/bb762164(v=vs.85).aspx) would be a simple solution, e.g.

void CopyFiles(LPCTSTR pFrom, LPCTSTR pTo) {

  TCHAR acFrom[MAX_PATH], acTo[MAX_PATH];
  SHFILEOPSTRUCT sfo;
  ZeroMemory(&sfo, sizeof(SHFILEOPSTRUCT));

  // double NULL terminators required
  _stprintf(acFrom,"%s\0\0",pFrom);
  _stprintf(acTo,"%s\0\0",pTo);

  sfo.wFunc = FO_COPY;
  sfo.pFrom = acFrom;
  sfo.pTo = acTo;
  sfo.fFlags = FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR | FOF_NOERRORUI | FOF_SILENT;

  SHFileOperation(&sfo);
}

Open in new window

Author

Commented:
this windows base and what is MAX_PATH
should I set that
jkr
Top Expert 2012
Commented:
MAX_PATH is already defined in windows.h, no need to set that. What do you mean with "windows base"?

Author

Commented:
I bush of stuff is not working for me is this c++ or c
jkr
Top Expert 2012
Commented:
This is plain C code, what errors are you getting?

Author

Commented:
--------------------Configuration: ediparse_nicepak - Win32 Debug--------------------
Compiling...
ediParse.c
F:\Projects\GMG\ediparse_NicePak\ediParse.c(840) : warning C4013: '_stprintf' undefined; assuming extern returning int
F:\Projects\GMG\ediparse_NicePak\ediParse.c(889) : warning C4013: 'Copyfiles' undefined; assuming extern returning int

ediParse.obj - 0 error(s), 2 warning(s)
jkr
Top Expert 2012
Commented:
Hmm, try adding

#include <tchar.h>

"'Copyfiles' undefined" points to a typo, did you mean 'CopyFiles'?

Author

Commented:
yes I fix that Copyfiles is a typo

Author

Commented:
//Great Job I just have to test that it is working.

//this is how i am using it.

strcpy(pfrom , "C:\\Inetpub\\ftproot\\ODFL\\ODFL214*.*");
strcpy(acTo , "C:\\inetpub\\ftproot\\NicePak");

CopyFiles(pfrom,acTo);

  void CopyFiles(LPCTSTR pFrom, LPCTSTR pTo)
 
  {

   TCHAR acFrom[MAX_PATH], acTo[MAX_PATH];
   SHFILEOPSTRUCT sfo;
   ZeroMemory(&sfo, sizeof(SHFILEOPSTRUCT));

   // double NULL terminators required
   _stprintf(acFrom,"%s\0\0",pFrom);
   _stprintf(acTo,"%s\0\0",pTo);

   sfo.wFunc = FO_COPY;
   sfo.pFrom = acFrom;
   sfo.pTo = acTo;
   sfo.fFlags = FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR | FOF_NOERRORUI | FOF_SILENT;

  SHFileOperation(&sfo);
  }
jkr
Top Expert 2012
Commented:
Should work - how are your 'pfrom' and 'acTo' declared? Actually, you coudl as well try the following:

CopyFiles("C:\\Inetpub\\ftproot\\ODFL\\ODFL214*.*","C:\\inetpub\\ftproot\\NicePak");

Open in new window

Author

Commented:
New Error when try to run

Deleting intermediate files and output files for project 'ediparse_nicepak - Win32 Debug'.
--------------------Configuration: ediparse_nicepak - Win32 Debug--------------------
Compiling...
ediParse.c
Linking...
LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
Debug/ediparse_nicepak.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

ediparse_nicepak.exe - 2 error(s), 0 warning(s)
jkr
Top Expert 2012
Commented:
This indicates that your project is set to create a GUI app instead of a console app. To change that, open your project's properties (ALT+F7), go to "Configuration Properties|Linker|System" and change "SubSystem" from "Windows" to "Console".

Author

Commented:
cant find it ( Configuration Properties|Linker|System )

Author

Commented:
my IDE is Visual c++ 6.0
jkr
Top Expert 2012
Commented:
Ah, OK - then try "Linker|Command Line" and change "/SUBSYSTEM:WINDOWS" to "/SUBSYSTEM:CONSOLE" (IIRC)

Author

Commented:
ok no error now
but the files did not copy

Author

Commented:
this the name of one of the file

ODFL214201201171317.txt
jkr
Top Expert 2012
Commented:
Can you post the complete code?

Author

Commented:
YES
jkr
Top Expert 2012
Commented:
Just go on then ;o)

Author

Commented:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <direct.h>
#include <time.h>
#include <malloc.h>
#include <math.h>
#include <conio.h>
#include <windows.h>
#include <tchar.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <io.h>
#include "../herb.h"


struct	tm *currtime;
time_t	aclock;
int		nper, wcount, i, n, fsep, eor, ifield, lno;
char	ans[80], istr[32767], rectyp[256], *ptr;
char	cname[128], czip[20], cid[16], ncid[80], w[80][256], name_type[16], batchDate[16], groupType[12];
FILE	*infile, *orderfile, *statusfile, *imagefile, *errfile, *histfile, *nicepakfile;
char	inputFileName[256];
char	*rtype[]={"ISA", "IEA", "GS", "GE", "ST", "SE"};
struct	_finddata_t c_file;
long	hFile, total_size;
char	imagedir[256];
char pfrom[256], acTo[256];

struct
	{
	char pro_num[64];
	char pro_date[64];
	char bol_num[64];
	char bol_date[64];
	char ship_date[64];
	char pay_type[64];
	char ref_num[64];
	double net_due;
	long total_wgt;
	char sh_name[64];
	char sh_addr[64];
	char sh_city[64];
	char sh_state[16];
	char sh_zip[16];
	char cn_name[64];
	char cn_addr[64];
	char cn_city[64];
	char cn_state[16];
	char cn_zip[16];
	char bt_name[64];
	char bt_addr[64];
	char bt_city[64];
	char bt_state[16];
	char bt_zip[16];
	char customerid[64];
	struct
		{
		int  lineno;
		char desc[128];
		char units[16];
		char fclass[8];
		char wgt[16];
		char qty[16];
		double amt;
		} line_item[1000];
	} o210;


struct
	{
	char pro_num[64];
	char bol_num[64];
	char ref_num[64];
	char sh_name[64];
	char sh_addr[64];
	char sh_city[64];
	char sh_state[16];
	char sh_zip[16];
	char cn_name[64];
	char cn_addr[64];
	char cn_city[64];
	char cn_state[16];
	char cn_zip[16];
	char bt_name[64];
	char customerid[64];
	char wgt[16];
	char qty[16];
	char status_code[16];
	char status_date[16];
	char status_time[16];
	} o214;


// variables for 997
FILE	*file997;
char	FileName997[256];
int		trans_count, trans_accepted;
int		trans997_count, group997_count, set997_count, set997_num;
char	batchcode997[16];



BOOL PROC DupFile(char *sourceFilename, char *destinationFilename)
	{
	int		sfile, dfile, n;
	char	buf[32768];

	if( (sfile = open(sourceFilename, _O_RDONLY | _O_BINARY, _S_IREAD)) == 0 )
		return FALSE;
	if( (dfile = open(destinationFilename, _O_WRONLY | _O_CREAT | _O_TRUNC | _O_BINARY, _S_IWRITE)) == 0 )
		return FALSE;

	while( (n = read(sfile, buf, sizeof(buf))) > 0 ) write(dfile, buf, n);
	close(sfile);
	close(dfile);
	return TRUE;
	}


void PROC rmLeadingZeros(char *ibuf)
	{
	while( *ibuf == '0' )
		strcpy(ibuf, ibuf+1);
	}


void PROC makeOrder()
	{
	// add to the order file
	fprintf(orderfile, "PRObegin|odfl|%s|%s|%s|\n", o210.pro_num, o210.pro_date, o210.customerid);
	fprintf(orderfile, "BOL|%s|%s|\n", o210.bol_num, o210.bol_date);
	fprintf(orderfile, "Shipment|%s|%s|%s|%.2f|%d|\n", o210.ref_num, o210.ship_date, o210.pay_type, o210.net_due, o210.total_wgt);
	fprintf(orderfile, "Shipper|%s|%s|%s|%s|%s|\n", o210.sh_name, o210.sh_addr, o210.sh_city, o210.sh_state, o210.sh_zip);
	fprintf(orderfile, "Consignee|%s|%s|%s|%s|%s|\n", o210.cn_name, o210.cn_addr, o210.cn_city, o210.cn_state, o210.cn_zip);
	fprintf(orderfile, "BillTo|%s|%s|%s|%s|%s|\n", o210.bt_name, o210.bt_addr, o210.bt_city, o210.bt_state, o210.bt_zip);
	for( i=0; i<100; i++ )
		{
		if( o210.line_item[i].lineno != 0 )
			{
			if( strncmp(o210.line_item[i].desc, "Minimum Charge", 14) == 0) continue;
			if( strncmp(o210.line_item[i].desc, "FUEL", 4) == 0) continue;
			if( strncmp(o210.line_item[i].desc, "Discount", 8) == 0 ) continue;
			if( strncmp(o210.line_item[i].desc, "Rated As", 8) == 0 ) continue;
			fprintf(orderfile, "line|%02d|%s|%s|%s|%s|%s|%.2f|\n", 
					o210.line_item[i].lineno, o210.line_item[i].qty, o210.line_item[i].units, o210.line_item[i].desc, o210.line_item[i].fclass, o210.line_item[i].wgt, o210.line_item[i].amt);
			}
		}
	fprintf(orderfile, "PROend|%s|\n", o210.pro_num);
	fflush(orderfile);
	// sample output
	//	PRObegin|odfl|3005923317|20040308|
	//	BOL|OSC500383423|20040308|
	//	Shipment|PO:14952|20040308|PP|173.48|
	//	Shipper|ACCURATE PARTITIONS|HIGHWAY 123 NORTH|TOCCOA|GA|30577|
	//	Consignee|INTERIOR PLUS|ROUTE 2 BOX22A|RAVENSWOOD|WV|26164|
	//	BillTo|ACCURATE PARTITIONS|C/O G M G TRANSPORTATION|NY|NY|11729|
	//	line|01|2|PCS|Stall Partitions, Doors, Posts or|050|1353|
	//	line|02|3|PCS|Catches or Latches, metal, NOI, in boxe|050|
	//	PROend|3005923317|

	// append to the historic file
	fprintf(histfile, "PRObegin|odfl|%s|%s|%s|\n", o210.pro_num, o210.pro_date, o210.customerid);
	fprintf(histfile, "BOL|%s|%s|\n", o210.bol_num, o210.bol_date);
	fprintf(histfile, "Shipment|%s|%s|%s|%.2f|\n", o210.ref_num, o210.ship_date, o210.pay_type, o210.net_due);
	fprintf(histfile, "Shipper|%s|%s|%s|%s|%s|\n", o210.sh_name, o210.sh_addr, o210.sh_city, o210.sh_state, o210.sh_zip);
	fprintf(histfile, "Consignee|%s|%s|%s|%s|%s|\n", o210.cn_name, o210.cn_addr, o210.cn_city, o210.cn_state, o210.cn_zip);
	fprintf(histfile, "BillTo|%s|%s|%s|%s|%s|\n", o210.bt_name, o210.bt_addr, o210.bt_city, o210.bt_state, o210.bt_zip);
	for( i=0; i<100; i++ )
		{
		if( o210.line_item[i].lineno != 0 )
			{
			if( strncmp(o210.line_item[i].desc, "Minimum Charge", 14) == 0) continue;
			if( strncmp(o210.line_item[i].desc, "FUEL", 4) == 0) continue;
			if( strncmp(o210.line_item[i].desc, "Discount", 8) == 0 ) continue;
			if( strncmp(o210.line_item[i].desc, "Rated As", 8) == 0 ) continue;
			fprintf(histfile, "line|%02d|%s|%s|%s|%s|%s|%.2f|\n", 
					o210.line_item[i].lineno, o210.line_item[i].qty, o210.line_item[i].units, o210.line_item[i].desc, o210.line_item[i].fclass, o210.line_item[i].wgt, o210.line_item[i].amt);
			}
		}
	fprintf(histfile, "PROend|%s|\n", o210.pro_num);
	fflush(histfile);


	// request the images
	if( *o210.customerid > 0 )
		{
		fprintf(imagefile, "%s", o210.pro_num);
		fflush(imagefile);
		}
	}


void PROC makeStatus()
	{
	fprintf(statusfile, "PRObegin|odfl|%s|%s|%s|%s|%s|%s|%s|\n", o214.pro_num, o214.customerid, o214.bt_name, o214.bol_num, o214.ref_num, o214.qty, o214.wgt);
	fprintf(statusfile, "Shipper|%s|%s|%s|%s|%s|\n", o214.sh_name, o214.sh_addr, o214.sh_city, o214.sh_state, o214.sh_zip);
	fprintf(statusfile, "Consignee|%s|%s|%s|%s|%s|\n", o214.cn_name, o214.cn_addr, o214.cn_city, o214.cn_state, o214.cn_zip);
	fprintf(statusfile, "Status|%s|%s|%s|\n", o214.status_code, o214.status_date, o214.status_time);
	fprintf(statusfile, "PROend|%s|\n", o214.pro_num);
	fflush(statusfile);

	// request the image
	if( *o214.customerid > 0 )
		{
		fprintf(imagefile, "%s", o214.pro_num);
		fflush(imagefile);
		}
	}


int PROC getnextrec(char *until)
	{
	int ch, n, nbuf = 256;
	char buf[256];

	// initialize the buffer
	memset(buf, 0, nbuf);

	// make all fields into empty strings
	for( n=0; n<80; n++ ) *w[n] = 0;
	
	// load the buffer setting the field pointers as we go
	ifield = 0;
	n = 0;
	memset(buf, 0, nbuf);
	while( (ch = getc(infile)) != EOF )
		{
		if( ch == eor )
			{
			strcpy(w[ifield], buf);
			if( STREQ(w[0], until) )
				return TRUE;
			else
				return FALSE;
			}
		if( ch == '\n' || ch == '\r' )
			{
			continue;
			}
		if( ch == fsep )
			{
			strcpy(w[ifield++], buf);
			n = 0;
			memset(buf, 0, nbuf);
			}
		else
			{
			if( n < nbuf ) buf[n++] = ch;
			}
		}
	return TRUE;
	}


void PROC process_210_group(char *groupnum)
	{

	// write the 997 ST records
	set997_count++;
	set997_num++;
	fprintf(file997, "%s%c%s%c%d%c",
		"ST", fsep, "997", fsep, set997_num, eor);
	fflush(file997);
	trans997_count = 1;

	trans_count = 0;
	trans_accepted = 0;

	// write the 997 AK1 record ... records start of this receive group
	fprintf(file997, "%s%c%s%c%s%c", 
		"AK1", fsep, "IM", fsep, groupnum, eor);
	fflush(file997);
	trans997_count++;

	while( !getnextrec("GE") )	
		{
		// it must be a Segment Start record
		if( STRNE(w[0], "ST") )
			{
			fprintf(errfile, "ODFL: Missing ST record ... found ");
			for( i=0; i<=ifield; i++ ) fprintf(errfile, "|%s", w[i]);
			fprintf(errfile, "|\n");
			continue;
			}
		memset(&o210, 0, sizeof(o210));

		// do the 997 processing
		//
		// write the 997 AK2 record
		fprintf(file997, "%s%c%s%c%s%c", 
			"AK2", fsep, w[1], fsep, w[2], eor);
		fflush(file997);
		trans997_count++;
	
		if( STRNE(w[1], "210") )
			{
			// skip this transaction if not a 210
			while( !getnextrec("SE") );	

			// write the 997 AK5 record
			fprintf(file997, "%s%c%s%c", 
				"AK5", fsep, "R", eor);
			fflush(file997);
			trans997_count++;
			trans997_count++;
			}
		else
			{
			while( !getnextrec("SE") )	
				{
				// process the details of this transaction

				// main header
				if( STREQ(w[0], "B3") )
					{
					strcpy(o210.pro_num, w[2]);
					strcpy(o210.bol_num, w[3]);
					strcpy(o210.pay_type, w[4]);
					strcpy(o210.bol_date, w[6]);
					strcpy(o210.pro_date, batchDate);
					o210.net_due = atof(w[7]) / 100.0;
					// remove any leading zeros from the pronum
					while( *o210.pro_num == '0' ) strcpy(o210.pro_num, o210.pro_num+1);
					continue;
					}
				// reference
				if( STREQ(w[0], "N9") )
					{
					if( (strlen(w[1]) + strlen(w[2]) + 1) < sizeof(o210.ref_num) )
						{
						*(w[2] + (sizeof(o210.ref_num) - strlen(w[1]) - 2)) = 0;
						}
					strcpy(o210.ref_num, w[1]);
					strcat(o210.ref_num, ":");
					strcat(o210.ref_num, w[2]);
					continue;
					}
				// ship date
				if( STREQ(w[0], "G62") && STREQ(w[1], "86"))
					{
					strcpy(o210.ship_date, w[2]);
					continue;
					}
				// name/address
				if( STREQ(w[0], "N1") )
					{
					strcpy(name_type, w[1]);
					if( STREQ(name_type, "SH") )
						strcpy(o210.sh_name, w[2]);
					else if( STREQ(name_type, "CN") )
						strcpy(o210.cn_name, w[2]);
					else if( STREQ(name_type, "BT") )
						{
						strcpy(o210.bt_name, w[2]);
						strcpy(o210.customerid, w[4]);
						}
					continue;
					}
				if( STREQ(w[0], "N3") )
					{
					if( STREQ(name_type, "SH") )
						strcpy(o210.sh_addr, w[1]);
					else if( STREQ(name_type, "CN") )
						strcpy(o210.cn_addr, w[1]);
					else if( STREQ(name_type, "BT") )
						strcpy(o210.bt_addr, w[1]);
					continue;
					}
				if( STREQ(w[0], "N4") )
					{
					// fix a zip+4
					i = strlen(w[3]);
					if( i > 6 ) *(w[3] + 5) = 0;
					if( STREQ(name_type, "SH") )
						{
						strcpy(o210.sh_city, w[1]);
						strcpy(o210.sh_state, w[2]);
						strcpy(o210.sh_zip, w[3]);
						}
					else if( STREQ(name_type, "CN") )
						{
						strcpy(o210.cn_city, w[1]);
						strcpy(o210.cn_state, w[2]);
						strcpy(o210.cn_zip, w[3]);
						}
					else if( STREQ(name_type, "BT") )
						{
						strcpy(o210.bt_city, w[2]);
						strcpy(o210.bt_state, w[2]);
						strcpy(o210.bt_zip, w[3]);
						}
					continue;
					}
				// line items
				if( STREQ(w[0], "LX") )
					{
					lno = atoi(w[1]);
					o210.line_item[lno].lineno = lno;
					continue;
					}
				if( STREQ(w[0], "L0") )
					{
					lno = atoi(w[1]);
					if( *w[4] != 0 )
						{
						strcpy(o210.line_item[lno].wgt, w[4]);
						strcpy(o210.line_item[lno].qty, w[8]);
						strcpy(o210.line_item[lno].units, w[9]);
						}
					continue;
					}
				if( STREQ(w[0], "L1") )
					{
					lno = atoi(w[1]);
					o210.line_item[lno].amt = atof(w[4])/100.0;
					continue;
					}
				if( STREQ(w[0], "L5") )
					{
					lno = atoi(w[1]);
					strcpy(o210.line_item[lno].desc, w[2]);
					continue;
					}
				if( STREQ(w[0], "L7") )
					{
					lno = atoi(w[1]);
					strcpy(o210.line_item[lno].fclass, w[7]);
					continue;
					}
				// total weight
				if( STREQ(w[0], "L3") )
					{
					o210.total_wgt = atol(w[1]);
					continue;
					}
				}

			// write the 997 AK5 record
			fprintf(file997, "%s%c%s%c",
				"AK5", fsep, "A", eor);
			fflush(file997);
			trans997_count++;

			trans_count++;
			trans_accepted++;

			// make the order record and request the images
			makeOrder();
			}
		}

	// write the 997 AK9 record
	trans997_count++;
	fprintf(file997, "%s%c%s%c%d%c%d%c%d%c",
		"AK9", fsep, "A", fsep, trans_count, fsep, trans_count, fsep, trans_accepted, eor);
	fflush(file997);

	// write the 997 SE record
	trans997_count++;
	fprintf(file997, "%s%c%d%c%d%c",
		"SE", fsep, trans997_count, fsep, set997_num, eor);
	fflush(file997);

	return;
	}


void PROC process_214_group(char *groupnum)
	{

	// write the 997 ST records
	set997_count++;
	set997_num++;
	fprintf(file997, "%s%c%s%c%d%c",
		"ST", fsep, "997", fsep, set997_num, eor);
	fflush(file997);
	trans997_count = 1;

	trans_count = 0;
	trans_accepted = 0;

	// write the 997 AK1 record ... records start of this receive group
	fprintf(file997, "%s%c%s%c%s%c", 
		"AK1", fsep, "QM", fsep, groupnum, eor);
	fflush(file997);
	trans997_count++;

	while( !getnextrec("GE") )	
		{
		// it must be a Segment Start record
		if( STRNE(w[0], "ST") )
			{
			fprintf(errfile, "ODFL: Missing ST record ... found ");
			for( i=0; i<=ifield; i++ ) fprintf(errfile, "|%s", w[i]);
			fprintf(errfile, "|\n");
			continue;
			}
		memset(&o214, 0, sizeof(o214));

		// do the 997 processing
		//
		// write the 997 AK2 record ... records this transaction
		fprintf(file997, "%s%c%s%c%s%c", 
			"AK2", fsep, w[1], fsep, w[2], eor);
		fflush(file997);
		trans997_count++;

		if( STRNE(w[1], "214") )
			{
			// skip this transaction if not a 214
			while( !getnextrec("SE") );	

			// write the 997 AK5 record
			fprintf(file997, "%s%c%s%c",
				"AK5", fsep, "R", eor);
			fflush(file997);
			trans997_count++;
			trans_count++;
			}
		else
			{
			// process the details of this transaction
			while( !getnextrec("SE") )	
				{

				// main header
				if( STREQ(w[0], "B10") )
					{
					strcpy(o214.pro_num, w[1]);
					rmLeadingZeros(o214.pro_num);
					strcpy(o214.bol_num, w[2]);
					continue;
					}
				// reference
				if( STREQ(w[0], "L11") )
					{
					if( (strlen(o214.ref_num) + strlen(w[2]) + strlen(w[1]) + 4) > sizeof(o214.ref_num) )
						{
						continue;
						}
					if( strlen(o214.ref_num) > 0 ) 
						{
						strcat(o214.ref_num, " / ");
						}
					strcat(o214.ref_num, w[2]);
					strcat(o214.ref_num, ":");
					strcat(o214.ref_num, w[1]);
					continue;
					}
				// name/address
				if( STREQ(w[0], "N1") )
					{
					strcpy(name_type, w[1]);
					if( STREQ(name_type, "SH") )
						strcpy(o214.sh_name, w[2]);
					else if( STREQ(name_type, "CN") )
						strcpy(o214.cn_name, w[2]);
					else if( STREQ(name_type, "BT") )
						{
						strcpy(o214.bt_name, w[2]);
						strcpy(o214.customerid, w[4]);
						rmLeadingZeros(o214.customerid);
						}
					continue;
					}
				if( STREQ(w[0], "N3") )
					{
					if( STREQ(name_type, "SH") )
						strcpy(o214.sh_addr, w[1]);
					else if( STREQ(name_type, "CN") )
						strcpy(o214.cn_addr, w[1]);
					}
				if( STREQ(w[0], "N4") )
					{
					// fix zip+4
					i = strlen(w[3]);
					if( i > 7 ) *(w[3] + 5) = 0;
					if( STREQ(name_type, "SH") )
						{
						strcpy(o214.sh_city, w[1]);
						strcpy(o214.sh_state, w[2]);
						strcpy(o214.sh_zip, w[3]);
						}
					else if( STREQ(name_type, "CN") )
						{
						strcpy(o214.cn_city, w[1]);
						strcpy(o214.cn_state, w[2]);
						strcpy(o214.cn_zip, w[3]);
						}
					continue;
					}
				if( STREQ(w[0], "AT7") )
					{
					if( *w[1] != 0 )
						strcpy(o214.status_code, w[1]);
					else
						strcpy(o214.status_code, w[3]);
					strcpy(o214.status_date, w[5]);
					strcpy(o214.status_time, w[6]);
					continue;
					}
				if( STREQ(w[0], "AT8") )
					{
					strcpy(o214.wgt, w[3]);
					strcpy(o214.qty, w[4]);
					continue;
					}
				}

		// write the 997 AK5 record ... accepts this transaction
		fprintf(file997, "%s%c%s%c", 
			"AK5", fsep, "A", eor);
		fflush(file997);
		trans997_count++;

		trans_count++;
		trans_accepted++;

		//place my function here for nicepak 214 if streq finds Nicepak
		// I dont need to copy the info out of the array just write the 
		// format the 214 exactly like the nice pak 214 documentaion
		// directly to nicepak 214 file

		

		// make the status record
		makeStatus();
		}
	}

	// write the 997 AK9 record
	trans997_count++;
	fprintf(file997, "%s%c%s%c%d%c%d%c%d%c",
		"AK9", fsep, "A", fsep, trans_count, fsep, trans_count, fsep, trans_accepted, eor);
	fflush(file997);

	// write the 997 SE record
	trans997_count++;
	fprintf(file997, "%s%c%d%c%d%c",
		"SE", fsep, trans997_count, fsep, set997_num, eor);
	fflush(file997);

	return;
	}


void PROC skip_unknown_group()
	{
	while( !getnextrec("GE") );	
	return;
	}


int PROC process_set(char *infilename)
	{
	char	outfilename[256];

	// get the current time
	time(&aclock);
	currtime = localtime(&aclock);

	// create the archive
	sprintf(outfilename, "F:\\gmg_edi\\odfl\\old_input\\%s", infilename);
	if( !DupFile(infilename, outfilename) )
		{
		fprintf(errfile, "ODFL: Archive copy failed\n");
		return 99;
		}


	if( (infile = fopen(infilename, "r")) == NULL )
		{
		fprintf(errfile, "ODFL: input file not found\n");
		return 99;
		}

	// get the EDI control information for the file
	//
	// Get the first record.  It must be the ISA Header
	for( i=0; i<3; i++ ) istr[i] = getc(infile); istr[i] = 0;
	if( STRNE(istr, "ISA") )
		{
		fprintf(errfile, "ODFL: NO ISA record\n");
		return 99;
		}

	// the next character is the field seperator
	fsep = getc(infile);

	//
	// next find the EOR  It is the 106th real character because the ISA is fixed length
	fseek(infile, 0, SEEK_SET);
	i = 0;
	while( i < 106 )
		{
		eor = getc(infile);
		if( eor == '\n' || eor == '\r' ) continue;
		i++;
		}
	//
	// rewind the stream so program starts at the beginning of the file
	fseek(infile, 0, SEEK_SET);


	// create the 997 file
	strcpy(FileName997, infilename);
	memcpy(FileName997+4, "997", 3);

	if( (file997 = fopen("odfl.997", "w")) == NULL )
		{
		fprintf(errfile, "ODFL: could not create tmp 997 file\n");
		return 99;
		}

	// Process the  records.
	// They are in heirarchical groups:
	//	ISA
	//		GS
	//			ST
	//				detail
	//			SE
	//		GE
	//	IEA



	// start the batch counter
	group997_count = 0;

	// read the ISA record into the field array
	while (	!getnextrec("EOF") )
		{
		if( STRNE(w[0], "ISA") )
			{
			fprintf(errfile, "\nODFL: NO ISA record\n");
			return 99;
			}

		// 997 get the data needed from the ISA
		strcpy(batchcode997, w[13]);

		// write the 997 ISA record
		fprintf(file997, "%s%c%s%c%s%c%s%c%s%c%s%c%s%c%s%c%s%c%02d%02d%02d%c%02d%02d%c%s%c%s%c%s%c%s%c%s%c%s%c",
			"ISA", fsep, w[1], fsep, w[2], fsep, w[3], fsep, w[4], fsep, w[7], fsep, w[8], fsep, w[5], fsep, w[6], fsep,
			currtime->tm_year % 100, currtime->tm_mon + 1, currtime->tm_mday, fsep, currtime->tm_hour, currtime->tm_min, fsep,
			w[11], fsep, w[12], fsep, batchcode997, fsep, w[14], fsep, w[15], fsep, w[16], eor);
		fflush(file997);

		
		// get records until the IEA record is retrieved

		while( !getnextrec("IEA") )	
			{

			// it must be a Group Start record
			if( STRNE(w[0], "GS") )
				{
				fprintf(errfile, "\nODFL: NO GS record\n");
				return 99;
				}
			strcpy(batchDate, w[4]);
			strcpy(groupType, w[1]);

			// write the 997 GS record
			group997_count++;
			set997_count = 0;
			set997_num = group997_count * 10000;
			fprintf(file997, "%s%c%s%c%s%c%s%c%04d%02d%02d%c%02d%02d%c%d%c%s%c%s%c",
				"GS", fsep, "FA", fsep, w[3], fsep, w[2], fsep,
				currtime->tm_year + 1900, currtime->tm_mon + 1, currtime->tm_mday, fsep, currtime->tm_hour, currtime->tm_min, fsep,
				group997_count, fsep, "X", fsep, "004010", eor);
			fflush(file997);

			if( STREQ(groupType, "IM") ) 
				{
				process_210_group(w[6]);
				}
			else if( STREQ(groupType, "QM") )
				{
				process_214_group(w[6]);
				}
			else
				{
				fprintf(errfile, "ODFL: Invalid group type %s\n", groupType);
				skip_unknown_group();
				}
			}

		// write the 997 GE record
		fprintf(file997, "%s%c%d%c%d%c",
			"GE", fsep, set997_count, fsep, group997_count, eor);
		fflush(file997);

		// write the 997 IEA record and close the file
		fprintf(file997, "%s%c%d%c%s%c",
			"IEA", fsep, group997_count, fsep, batchcode997, eor);
		}

	fclose(file997);
	fclose(infile);
	remove(infilename);


	// convert the 997 file to 80 characters and ftp it
	if( (file997 = fopen(FileName997, "w")) == NULL )
		{
		fprintf(errfile, "ODFL: could not create 997 file %s\n", FileName997);
		return 99;
		}

	if( (infile = fopen("odfl.997", "r")) == NULL )
		{
		fprintf(errfile, "ODFL: could not open tmp 997 file\n");
		return 99;
		}

	while( (n = fread(istr, 1, 80, infile)) > 0 )
		{
		istr[n] = 0;
		fprintf(file997, "%s\n", istr);
		}
	fclose(file997);
	fclose(infile);
	remove("odfl.997");

	return 0;
	}


  void CopyFiles(LPCTSTR pFrom, LPCTSTR pTo)
  
  {

   TCHAR acFrom[MAX_PATH], acTo[MAX_PATH];
   SHFILEOPSTRUCT sfo;
   ZeroMemory(&sfo, sizeof(SHFILEOPSTRUCT));

   // double NULL terminators required
   _stprintf(acFrom,"%s\0\0",pFrom);
   _stprintf(acTo,"%s\0\0",pTo);

   sfo.wFunc = FO_COPY;
   sfo.pFrom = acFrom;
   sfo.pTo = acTo;
   sfo.fFlags = FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR | FOF_NOERRORUI | FOF_SILENT;

  SHFileOperation(&sfo);
  }

int PROC main(int argc, char *argv[]) 
	{

	
	//strcpy(pfrom , "C:\\Inetpub\\ftproot\\ODFL\\ODFL214*.*");
   //strcpy(acTo , "C:\\inetpub\\ftproot\\NicePak");
	//C:\inetpub\ftproot\NicePak
	//C:\inetpub\ftproot\NicePak
	CopyFiles("C:\\Inetpub\\ftproot\\ODFL\\ODFL214*.*","C:\\inetpub\\ftproot\\NicePak");

	//
	// open the error file
	if( (errfile = fopen("F:\\gmg_edi\\odfl\\EDI_errors.txt", "a" )) == NULL )
		{
		return 99;
		}
	//
	// change to the data path
	if( chdir("C:\\Inetpub\\ftproot\\ODFL") == -1 )
		{
		fprintf(errfile, "ODFL: No data path found\n");
		return 99;
		}

	//
	// create the output files
	if( (orderfile = fopen("F:\\gmg_edi\\odfl\\orders.txt", "a" )) == NULL )
		{
		fprintf(errfile, "ODFL: Could not create order file\n");
		return 99;
		}

	if( (imagefile = fopen("F:\\gmg_edi\\odfl\\imagereq.txt", "a" )) == NULL )
		{
		fprintf(errfile, "ODFL: Could not create image file\n");
		return 99;
		}
   	if( (statusfile = fopen("F:\\gmg_edi\\status.txt", "a" )) == NULL )
		{
		fprintf(errfile, "ODFL: Could not create status file\n");
		return 99;
		}


	// append the orders to the historic file
	histfile = fopen("F:\\gmg_edi\\odfl\\old_input\\Historic_Orders.txt", "a");


	// Find first file in the INPUT directory
	hFile = _findfirst( "ODFL2*.*", &c_file );
	if( (*c_file.name != '.') && !(c_file.attrib & _A_SUBDIR) )
		{
		process_set(c_file.name);
		}

	/* Find the rest of the files */
	while( _findnext( hFile, &c_file ) == 0 )
		{
		if( (*c_file.name != '.') && !(c_file.attrib & _A_SUBDIR) )
			{
			process_set(c_file.name);
			}
		}
	_findclose( hFile );

	fclose(orderfile);
	fclose(statusfile);
	fclose(histfile);

	return 0;
	}

Open in new window

jkr
Top Expert 2012
Commented:
Hmm, do you get an error message if you remove the 'FOF_NOERRORUI | FOF_SILENT' flags?

Author

Commented:
that did it let me try it now

Author

Commented:
okay no error when I took out these two things and rebuild all
however the files did not copy

i saw this in the debug tab

Loaded 'ntdll.dll', no matching symbolic information found.
Loaded 'C:\Windows\System32\kernel32.dll', no matching symbolic information found.
Loaded 'C:\Windows\System32\shell32.dll', no matching symbolic information found.
Loaded 'C:\Windows\System32\msvcrt.dll', no matching symbolic information found.
Loaded 'C:\Windows\System32\gdi32.dll', no matching symbolic information found.
Loaded 'C:\Windows\System32\user32.dll', no matching symbolic information found.
Loaded 'C:\Windows\System32\advapi32.dll', no matching symbolic information found.
Loaded 'C:\Windows\System32\rpcrt4.dll', no matching symbolic information found.
Loaded 'C:\Windows\System32\shlwapi.dll', no matching symbolic information found.
Loaded 'C:\Windows\System32\TSAPPCMP.dll', no matching symbolic information found.
Loaded 'C:\Windows\System32\imm32.dll', no matching symbolic information found.
Loaded 'C:\Windows\System32\msctf.dll', no matching symbolic information found.
Loaded 'C:\Windows\System32\lpk.dll', no matching symbolic information found.
Loaded 'C:\Windows\System32\usp10.dll', no matching symbolic information found.
Loaded 'C:\Windows\winsxs\x86_microsoft.windows.common-controls_6595b64144ccf1df_6.0.6002.18305_none_5cb72f2a088b0ed3\comctl32.dll', no matching symbolic information found.
Loaded 'C:\Windows\System32\oleaut32.dll', no matching symbolic information found.
Loaded 'C:\Windows\System32\ole32.dll', no matching symbolic information found.
Loaded 'C:\Windows\System32\uxtheme.dll', no matching symbolic information found.
Loaded 'C:\Windows\System32\clbcatq.dll', no matching symbolic information found.
Loaded 'C:\Windows\winsxs\x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82.6002.18305_none_88f3a38569c2c436\comctl32.dll', no matching symbolic information found.
Loaded 'C:\Windows\System32\duser.dll', no matching symbolic information found.
Loaded 'C:\Windows\System32\xmllite.dll', no matching symbolic information found.
Loaded 'C:\Windows\System32\oleacc.dll', no matching symbolic information found.
Loaded 'C:\Windows\System32\msiltcfg.dll', no matching symbolic information found.
Loaded 'C:\Windows\System32\version.dll', no matching symbolic information found.
Loaded 'C:\Windows\System32\msi.dll', no matching symbolic information found.
Loaded 'C:\Windows\System32\sfc.dll', no matching symbolic information found.
Loaded 'C:\Windows\System32\sfc_os.dll', no matching symbolic information found.
Loaded 'C:\Windows\System32\setupapi.dll', no matching symbolic information found.
Loaded 'C:\Windows\System32\rsaenh.dll', no matching symbolic information found.
Loaded 'C:\Program Files\Common Files\Microsoft Shared\ink\skchui.dll', no matching symbolic information found.
Loaded 'C:\Program Files\Common Files\Microsoft Shared\ink\penusa.dll', no matching symbolic information found.
Loaded 'C:\Program Files\Common Files\Microsoft Shared\ink\penusa.dll', no matching symbolic information found.
Loaded 'C:\Windows\System32\propsys.dll', no matching symbolic information found.
The program 'F:\Projects\GMG\ediparse_NicePak\Debug\ediparse_nicepak.exe' has exited with code 0 (0x0).
jkr
Top Expert 2012
Commented:
Dont't worry about that, you'd have to instal the debug symbols from http://msdn.microsoft.com/en-us/windows/hardware/gg463028

Author

Commented:
so what is the next move

Author

Commented:
file copy message boxokay when I put the extension on the wild card it copy but a messagebox comes up

C:\\Inetpub\\ftproot\\ODFL\\ODFL214*.txt","C:\\inetpub\\ftproot\\NicePak");



file copy message box
when i click try again it work
Top Expert 2016
Commented:
the output looks like UNICODE mismatch.

you could try a modified version of jkr's CopyFiles which doesn't use the "T-Switch" but is for ANSI strings only.

void CopyFiles(const char * pFrom, const char * pTo)
{
    char acFrom[MAXPATH+2] = { '\0' }; // makes all zero and guarantees a double-zero at end after strcpy
    char acTo[MAXPATH+2]   = { '\0' };
    SHFILEOPSTRUCTA sfo = { 0 };

    strcpy(acFrom, pFrom);
    strcpy(acTo, pTo);
    sfo.wFunc = FO_COPY;
    sfo.pFrom = acFrom;
    sfo.pTo = acTo;
    sfo.fFlags = FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR | FOF_NOERRORUI | FOF_SILENT;

    SHFileOperationA(&sfo);
}

Open in new window


if that solves the issue your project is defined with UNICODE character set what could lead to a mixup when using LPCTSTR, TCHAR or winapi functions which have functions/structures with suffix A and suffix W for use of either ANSI or UNICODE strings.

Sara

Author

Commented:
I am getting errors

Compiling...
ediParse.c
F:\Projects\GMG\ediparse_NicePak\ediParse.c(836) : error C2065: 'MAXPATH' : undeclared identifier
F:\Projects\GMG\ediparse_NicePak\ediParse.c(836) : error C2057: expected constant expression
F:\Projects\GMG\ediparse_NicePak\ediParse.c(836) : error C2466: cannot allocate an array of constant size 0
F:\Projects\GMG\ediparse_NicePak\ediParse.c(837) : error C2057: expected constant expression
F:\Projects\GMG\ediparse_NicePak\ediParse.c(837) : error C2466: cannot allocate an array of constant size 0
Error executing cl.exe.

Author

Commented:
All the errors are steming from this two lines

 // makes all zero and guarantees a double-zero at end after strcpy
char acFrom[MAXPATH+2] = { '\0' };
char acTo[MAXPATH+2]   = { '\0' };

why do I need the additional plus 2
Top Expert 2016
Commented:
use MAX_PATH instead of MAXPATH. it was a typo.

Author

Commented:
yo great job both you

Author

Commented:
Awesome
Top Expert 2016

Commented:
the MAX_PATH + 2 is only for correctness cause the acFrom and acTo need two binary zero characters at end (cause actually you could pass a list of files where each file was separated by one zero char and the end is when two zero chars occur) . MAX_PATH is the maximum path length and in case anyone has used that maximum (what would be not the case) i added two more for the zero chars.

your project settings seem to have UNICODE enabled what doesn't matter as long as you were not using the TCHAR, LPCTSTR, _T ... types or WINAPI functions using those types.

i would recommend you change the character set used for the project to 'multi-byte character set' even if we found a workaround for the current problem. when calling the next winapi function you might get the same problems again.

Sara

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial