PDA

View Full Version : Creating a folder then dumping files into it!



ChrisMUK
07-30-2002, 04:56 AM
Hey

I need to know a code that i can get to create a folder then dump a load of files out of a .zip or something into the folder.

Is it possible?

Waldo2k2
07-31-2002, 04:20 PM
system("md c:\whatever");//makes the directory
system("mov c:\files\file.txt c:\whatever");//move to new directory

www.easydos.com has a listing of all the commands...copy and stuff may be better as opposed to move.

ChrisMUK
08-01-2002, 01:27 PM
I tried it but it doesn't work! :(

I don't really need to know it just want to see if it can be done!

shaik786
08-01-2002, 01:36 PM
system("md c:\whatever");//makes the directory
system("mov c:\files\file.txt c:\whatever");//move to new directory


Use double \ instead.
system("md c:\\whatever");

Waldo2k2
08-01-2002, 05:41 PM
thanks for helping him out shaik, i spaced on that one. :(

ChrisMUK
08-02-2002, 07:19 AM
Yeah i got that working.

ChrisMUK
08-02-2002, 07:25 AM
#include <stdlib.h>

int main()

{
system("md c:\\test");//makes the directory
system("mov c:\test.txt c:\test");//move to new directory
system("PAUSE");
return 0;
}

That move never worked.

I get this:
'mov' is not recognized as an internal or external command, operable program or batch file.
Press any key to continue.....

I tried doubling the \\ on the mov thing but it says:

cannot open output file Format.exe C:\Dev-C++\mingw32\bin\ld.exe
Permission denied
C:\Documents and Settings\Chris\Desktop\C++\Makefile.win
[Build Error] [Create.exe] Error 1


Any ideas?

ChrisMUK
08-02-2002, 08:04 AM
Ok thanks got that working.

But what i really want is anyway i can get it to take the file out of a .zip file and into the folder?

Waldo2k2
08-03-2002, 03:24 PM
dude, search for zip on the board, in the last month i know of at least 20 posts asking this same stupid question

ChrisMUK
08-04-2002, 06:44 AM
Well sorry but i didn't know did i!

Waldo2k2
08-04-2002, 03:59 PM
just giving you advice, when you search you'll usually come up with something. Theres been god knowns how many threads on this site.

ChrisMUK
08-04-2002, 04:44 PM
Thanks, i searched when you told me to didn't have much time to look at it. But i will have another look now.

Shadow
08-10-2002, 11:50 AM
To expand on Salem's advice for the zip file stuff, awhile ago I created 2 functions for zip file, with his code troubleshooting assistance. You may want to take a look at the following if it will help any:
#include "Install.h"

void ZipCheck ( char * FileCheck, char * Name )
{
FILE * Tmp;
if ( ( Tmp = fopen( FileCheck, "r" ) ) == 0 )
{
printf("%s not found, skipping.\n", Name);
}
else
{
/* Nothing */
}
fclose(Tmp);
}

void ZipExtract ( char * SourceFile, char * Destination, char * Name )
{
char * args[6];
args[0] = " -qq "; /* makes unzip.exe quiet */
args[1] = " -C "; /* make unzip.exe noncase-sensative */
args[2] = SourceFile;
args[3] = " -d "; /* create new subdirectory for file(s) */
args[4] = Destination;
args[5] = NULL; /* more output supression to unzip.exe */
printf("Copying..");
spawnv( P_WAIT, "d:\\unzip.exe", args );

printf("\b\b\b\b\b\b\b\b\bCopied - %s\n", Name);
}
For the code example at hand, I am using the unzip program found on this page (http://www.mame.net/downmain.html) for some of my C / C++ programs I code that help my emulation hobby along to move faster.

A common way to use the functions:
#include <stdio.h>

int main ( void )
{
ZipCheck("d:\\directory\\foo.zip", "Foo.zip");
/* arg 1 = zip file, arg 2 = commercial name of zip file */

ZipExtract("d:\\directory\\foo.zip", "c:\\NewDirectory", "Software name");
/* OR */
ZipExtract("d:\\directory\\foo.zip ReadMe.txt", "c:\\Newdirectory\\Docs", "ReadMe File");

return 0;
}
If the zip program at question will not work for you, replace it with another. Manipulate the spawn function setup to work in conjunction with the new zip program.

To even expand further:

#include <stdio.h>
#include <process.h>

int ZipCheck ( char * FileCheck, char * Name );
int ZipExtract ( char * SourceFile, char * Destination, char * Name );

int main ( void )
{
if ( ZipCheck("c:\\windows\\readme.zip", "ReadMeZip") == 0 )
{
ZipExtract("c:\\windows\\readme.zip",
"c:\\windows\\desktop",
"ReadMe");
}
else
{
printf("Exiting on error");
return 1;
}
return 0;
}

int ZipCheck ( char * FileCheck, char * Name )
{
FILE * Tmp;
if ( ( Tmp = fopen( FileCheck, "r" ) ) == 0 )
{
printf("%s not found, skipping.\n", Name);
return 1;
}
else
{
fclose(Tmp);
return 0;
}
}

int ZipExtract ( char * SourceFile, char * Destination, char * Name )
{
char * args[6];
args[0] = " -qq "; /* makes unzip.exe quiet */
args[1] = " -C "; /* make unzip.exe noncase-sensative */
args[2] = SourceFile;
args[3] = " -d "; /* create new subdirectory for file(s) */
args[4] = Destination;
args[5] = NULL; /* more output supression to unzip.exe */
printf("Copying..");
spawnv( P_WAIT, "c:\\windows\\command\\unzip.exe", args );

printf("\b\b\b\b\b\b\b\b\bCopied - %s\n", Name);
return 0;
}
The above program should work so long as you satisfy it's conditions for working.

ChrisMUK
08-13-2002, 03:20 PM
Ok thanks, i'll try it sometime just i have been busy!