-
Using fopen on a folder
Hey guys I'm currently writting a basic encryption program which works flawless on all types of files.
Unfortunately when I attempt to run it on a folder instead of individual files my fopen function always returns NULL.
Is there some sort of hidden file extension for Windows folders that I need to include with the folder name, or maybe some other way I should go about this?
Here is my basic open file code that works fine on all file types except folders:
Code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int count, key, random, flag;
char end;
char ORGfile[10] = "ORGfolder"; //original folder name
char ENCfile[10] = "ENCfolder"; //encrypted folder name
FILE *in, *out;
printf("\nEnter encryption key: ");
scanf("%s", &str);
key = atoi(str);
srand(key);
if (( in = fopen(ORGfile, "rb")) == NULL)
{
printf("\n\t\..........* ERROR: unable to open file for reading ***\n");
return(-1);
}
else
{
//the rest has been omitted since it has nothing to do with this question...
}
return(0);
}
-
http://www.cprogramming.com/cboard/s...der=descending
Use findfirst/findnext to locate each file/subfolder, then use fopen to open each file
-
I was hoping to avoid encrypting each file within the folder one-by-one.
I did figure out a way to kind of rig-it and force it to work. I simply used the rename() function within stdio.h to first rename the folder so it has filename with extension. It's a cheesy way to do it, but at least it works.
If anyone still knows how I can encrypt the entire folder in one shot instead of doing it file-by-file I would still appreciate your ideas.
I hate doing it with this chessy intermediate renaming step, but I will if all else fails.
Thanks...
-
folders
i don't know of any other ways but you brought up a good question "is there a hidden extension for folders", i don' think there is but i have another question. if folders have no extension then how come if i make a new file, called say H, with no extension, its not a folder? Is this a stupid question?
-
No stupid questions, just stupid people...(just kidding) =)
There is a function prototype in DIRECT.H called _mkdir() for creating directories. This is part of the Visual C++ 6.0 headers, although with other compilers the header might be called dir.h
-
>I was hoping to avoid encrypting each file within the folder one-by-one.
To "avoid" doing so, means you need to combine all files into one first. A bit pointless really.
>I simply used the rename() function within stdio.h to first rename the folder so it has filename with extension.
Do you know what a folder actually is? You cannot encrypt it, because it's not a true file, it more than likely just an entry in your OS allocation table.
>If anyone still knows how I can encrypt the entire folder in one shot instead of doing it file-by-file I would still appreciate your ideas.
Don't think there is any other way (other than I first suggested).... but I'd like someone to proove me wrong!
-
Yes I believe you are right. I thought at first that renaming the folder worked, but after closer inspection the program still had not encrypted the files. The only thing that had actually occured was the renaming of the folder.
Oh well, I guess I'll just have to do it with each file one-by-one. I was hoping to keep the program simple since the program is just for personal use.
Thank you to everyone that added their input on the subject...