#include<stdio.h>
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include <dir.h>
char *ruta;
char *current_directory(char *path)
{
strcpy(path, "X:\\");
path[0] = 'A' + getdisk();
getcurdir(0, path+3);
return(path);
}
void borra()
{
int x,y;
for(x=0;x<=80;x++)
for(y=0;y<=100;y++)
{ gotoxy(x,y);
printf(" ");
gotoxy(1,1);
}
}
void cambiar()
{
printf("ingresa la ruta que quieres cambiar: ");
gets(ruta);
chdir (ruta);
}
void dir()
{
struct ffblk ffblk;
int done;
printf("Directory listing of *.*\n");
done = findfirst("*.*",&ffblk,0);
while (!done)
{
printf(" %s\n", ffblk.ff_name);
done = findnext(&ffblk);
}
}
void copiar()
{
char copy[30];
FILE *entrada, *salida;
printf("dime el archivo que quieres copiar:");
fflush(stdin);
gets(copy);
entrada = fopen(copy, "rb");
printf( "fichero: %s \n", copy );
if(entrada != NULL )
{
fclose(entrada);
}
printf("ingresa la ruta que quieres cambiar: ");
fflush(stdin);
gets(ruta);
salida = fopen(ruta, "wb");
printf("fichero: %s\n ",ruta);
if(salida != NULL)
{
fclose(salida);
}
int ch;
while ((ch = fgetc(entrada))!=EOF)
fputc(ch, salida);
fclose(entrada);
fclose(salida);
};
void eliminar()
{
char nombre[24];
FILE *archivo;
printf("archivo a eliminar:");
fflush(stdin);
gets(nombre);
archivo = fopen( nombre, "r" );
printf( "fichero: %s", nombre );
if(archivo != NULL )
{
fclose(archivo);
if(remove(nombre) == 0)
printf( "\nEl archivo fue eiminado\n" );
else
printf( "\nNo se elimino\n" );
}
else
printf( ", no encontrado\n" );
}
void main()
{ char z,* texto;
int q,t,error;
q=0;
while(q==0)
{ char curdir[MAXPATH];
current_directory(curdir);
printf("\n%s ", curdir);
error=1;
fflush(stdin);
gets(texto);
printf("");
t=strcmp(texto,"");
if(t==0)
{
error=0;
}
t=strcmp(texto,"borra");
if(t==0)
{ borra();
error=0;
}
t=strcmp(texto,"salir");
if(t==0)
{ q++;
error=0;
}
t=strcmp(texto,"ruta");
if(t==0)
{ cambiar();
error=0;
}
t=strcmp(texto,"dir");
if(t==0)
{
dir();
error=0;
}
t=strcmp(texto,"copiar");
if(t==0)
{
copiar();
error=0;
}
t=strcmp(texto,"eliminar");
if(t==0)
{
eliminar();
error=0;
}
if(error==1)
printf("El comando es invalido\n");
}
}