Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi, I'm having a hard time tryin 1

Status
Not open for further replies.

reportbrazil

Technical User
Jun 10, 2002
9
US
Hi,

I'm having a hard time trying to figure out how to rename a file with the current date, so I can keep back-ups for a daily ftp routine.

Basically I have an output file sent to me every day and I have to ftp this file to a unix server.

I already put toghether the code to do that, as you can see below, but now I need to back-up the file before the ftp, so I'll overrite the file on the server. If anything goes wrong I must be able to re-send the file (maybe days ago).

The ftp part is working fine, even with the PGP encrypt/decrypt for ftp user/passwd protection (sorry for the Portuguese comments on the code...)

Please take a look at my code, which is a frankeinstein, built mostly from tips I've got here (and I've been looking for old answers too)... The next step will be to create a routine for cleansing very old backup files... But I'll get there when the time comes by.

Any help will be very appreciated. Please, don't laugh, I'm really a newby to C, C++, ... My code is almost idiotic #:cool:

Tks, Marcelo.

PS: I'm using the freeware dm V.8.28n (Digital Mars C/C++ Compiler) and a bunch of libraries I've got around.

Code below...

#include <stdio.h>
#include <windows.h>
#include <winbase.h>
#include <winsvc.h>
#include <dos.h>
#include <time.h>
#include<conio.h>

// Cria funcao p/ Data

struct date dateFunc()
{
struct date d;

getdate(&d);

return d;
};


void main() // Rotina Principal
{
struct date today;

today=dateFunc(); // Coleta a data atual

printf(&quot;%d-%d-%d.out\n&quot;,today.da_day, today.da_mon,today.da_year);

struct date novoarq;
// novoarq=(&quot;%d, %d, %d.out\n&quot;,today.da_day, today.da_mon,today.da_year);
// novoarq=(%d, %d, %d,today.da_day, today.da_mon,today.da_year);
//printf(%s);
{
MSG msg;
HWND hwnd;


system(&quot;copy *.out %s&quot;); // This is tricky, how do I replace the filename with the current date??
// I get a <whathever_name/variable (i.e %s)> filename here??

// It is working fine from here to the end...

system (&quot;pgpv -z <pass> ftp-in.pgp&quot;); /* Desencripta o arquivo de FTP */

printf(&quot;\nArquivo de FTP desencriptado\n\n&quot;); /* Imprime mensagem */

system (&quot;ftp -i -v -s:ftp-in&quot;); /* Envia os arquivos para o eBAN */

printf(&quot;\nArquivos transferidos\n\n&quot;); /* Imprime mensagem */

system (&quot;del ftp-in&quot;); /* Remove o arquivo de FTP */

printf(&quot;\nArquivo de FTP desencriptado removido\n\n&quot;); /* Imprime mensagem */

// return(0);

}

}
 
hmm ..

why not try &quot;rename&quot; - the function call ? will that help you ?

Code:
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>

int main(int argc, char *argv[]) {
	if (argc !=3) {
    	printf (&quot;Insufficient args: rename <oldnmae> <new name>\n&quot;);
        exit(0);
    }

    if (rename(argv[1], argv[2])) {
    	printf (&quot;Error: cannot rename %s to %s\n&quot;, argv[1], argv[2]);
        exit(-1);
    }
    return 0;
}

ofcourse you would somehow copy your &quot;date&quot; into a buffer first {may be use mem copy or strcpy or what ever }

br: nagi
 
Hey Nagi,

Your idea was very good... Thanks.

I compiled your code and now I'm working on the parameters to pass.

I'm almost there.

Regards,

Marcelo.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top