basic usage of MSDN Library functions

Hello everyone out there. So I have just started learning Windows Programming and here is a small project I was asked to complete. Can you please take a quick look and mention the mistakes I should correct. It is very urgent because I am going to take an exam in 2 days.

Thanks in advance.

The task is-
1. print the name of the current directory
2. Enter a new name, create a new directory with that new name and make it current.
3.Create a new file and write the contents of the .txt files of the primarily current directory in that file.

Here is the code I wrote.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <iostream>
#include <Windows.h>
using namespace std;
int main()
{
	char symbol; // for writing in a the final file
	CHAR name[100], a[100];
	WCHAR fname[100], a1[100];
	WIN32_FIND_DATA x;
	GetCurrentDirectory( 100,fname);
	for ( int i=0; i<100; i++ )
	name[i]=CHAR(fname[i]); // name[] contains the name of the primarily current directory
	cout<<"Current directory:" <<name<<endl;

	cout << "Enter a name for a new directory to be created:"<< endl;
	cin>>a;
	for(int i=0; i<100; i++ )
	a1[i]= WCHAR(a[i]);
	CreateDirectory(a1, NULL);
	SetCurrentDirectory(a1);
	cout << "The new current directory is: " << a << endl;

	CHAR filename[100];
	WCHAR ffilename[100];
	unsigned long z;
	cin>> filename;
	char n[10] = "\*.txt";
	strcat (name, n );
	WCHAR fname1[100];
	for(int i=0; i<100; i++ )
	fname1[i]= WCHAR(name[i]);
	HANDLE h=FindFirstFile (fname, &x);
	if (h==INVALID_HANDLE_VALUE)
	cout <<"error"<<endl;
        // file is created to write in  
	HANDLE g = CreateFile( TEXT( "final.txt"), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
	else
	{
		do
		{
			HANDLE l = CreateFile (x.cFileName,GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
			if (l==INVALID_HANDLE_VALUE)
	        cout <<"error"<<endl;
			else
			{
				if ( g== INVALID_HANDLE_VALUE)
				cerr<<"error\n";
				else
				ReadFile(l, &symbol, 1, &z,NULL )
			while (z)
			{
				WriteFile ( g, &symbol, 1, &z, NULL )
			}
				
			}
		}
	
	while( FindNextFile( h, &x) !=0 );
		FindClose(h);
	}
  CloseHandle(g);
  CloseHandle(l);
  return 0;
}

Last edited on
Topic archived. No new replies allowed.