So I started doing c programing and now I want to understand how file systems like fat 32 and NTFS works. So I want to know how to create a file transfering program. So here's a few questions....

1 How do I do it the portable way?
-find file size
-what data type to use in C to do the transfer
-explain the following:

from what I understand txt files are treated differently from other files

2 How to do it through windows
-how to call windows copy and cut functions, so that you get a popup dialog box that shows the trasfer in progress
-does it return anything to indicate a success or failure?

3 How to get file names from a given directory so that it is in the form of a 2d array
- how and where are those file names stored?

Recommended Answers

All 6 Replies

1 How do I do it the portable way?
-find file size

Since you mentioned C, so I cannot suggest you Boost::Filesystem
You will have to use platform specific codes like stat of unix and some equivalent function in windows with chain of #ifdef's. You can also use fstat , or fseek to the end of the file and then use ftell . But both of will give you exact result only in case of binary files because of differing representation of end-of-line.

-what data type to use in C to do the transfer

I guess you can use any(not sure)

3 How to get file names from a given directory so that it is in the form of a 2d array

Again this is very compiler/OS specific. You can see some examples here

Getting the list of files from a directory is not too difficult but is os-dependent. In C there is no portable way to do it. In C++ boost libraries have portable functions.

these code snippets show how to do it in both linux and ms-windows.

Well I'm not looking for a single function to do all this really. I mean alot of HDs are formated in NTFS or FAT32, so if I'm correct HDs have something called FAT which says where everything is located. So how is that data expressed. Is it a list of pointers followed by its file name? Can C even get to it?

Isn't C portable to the point you can creat an OS with it???

Well I'm not looking for a single function to do all this really. I mean alot of HDs are formated in NTFS or FAT32, so if I'm correct HDs have something called FAT which says where everything is located. So how is that data expressed. Is it a list of pointers followed by its file name? Can C even get to it?

I think it's possible, but it's very complex as described in this wikipedia article.

Each sector the contains a file has a pointer which can point to the next sector if the file occupies more than one. In this way, a file is basically a linked list of sectors.

Isn't C portable to the point you can creat an OS with it???

Yes, it's possible to create an operating system with C. However, because of the low level-ness needed in the program, a lot of assembly is required, forcing it to be hardware-specific.

Isn't C portable to the point you can creat an OS with it???

I think you have your concepts blurred there. Portability roughly impiles the same standard C code can be compiled on Windows system as well as Unix system. (of course provided you don't use external libraries).

Yes, C can be used to create an OS with it (and it has already been achieved), but for interfacing external devices like the hard drive or floppy drive, you need to write a program (ie a driver) which will act as an interpreter between the OS and the device.

Well I'm not looking for a single function to do all this really. I mean alot of HDs are formated in NTFS or FAT32, so if I'm correct HDs have something called FAT which says where everything is located. So how is that data expressed. Is it a list of pointers followed by its file name? Can C even get to it?

HD's have a File Alocation Table (FAT) or New Technology File System (NTFS) -- at least in Windows. They are two very different file systems. Linux uses FAT. Mac, who knows? A Google search will give you details of both.

Isn't C portable to the point you can creat an OS with it???

Yes. But you have to keep in mind each OS is written specifically for the hardware it runs on. So even though C is portable does not mean you can write an OS that's portable.

So I started doing c programing and now I want to understand how file systems like fat 32 and NTFS works. So I want to know how to create a file transfering program. So here's a few questions....

1 How do I do it the portable way?
-find file size

The only standard way is to read each character. Each OS and Compiler generally will have a way, but it's not portable.

-what data type to use in C to do the transfer

char

-explain the following:

2 How to do it through windows
-how to call windows copy and cut functions, so that you get a popup dialog box that shows the trasfer in progress
-does it return anything to indicate a success or failure?

Look at API information at http://MSDN.com

3 How to get file names from a given directory so that it is in the form of a 2d array
- how and where are those file names stored?

Very non-portable.

C itself knows nothing about hard drives, monitors, or keyboards. The I/O functions defined by C are just skeleton definitions to be defined via the standards by the compiler designers to work within the confines of the O/S.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.