how to leave a folder set for when to save? and a folder set to open files?

Asked

Viewed 74 times

-2

I would like to lock the folders, so that I could not fetch files or save files in other folders, only in the defined, EX Folders: c:\banco_de_dados and another call c:\FTP_Servidor

In case it would be to leave the path set to send the database to the server automatically.

source part:

begin

if OpenDialog1.Execute then
if SaveDialog1.Execute then

idftp1.Put(OpenDialog1.FileName, '/projeto_ftp/banco/' + ExtractFileName(SaveDialog1.FileName));

  // ShowMessage('Transferido');

idftp1.Get(SaveDialog1.FileName, '/projeto_ftp/' );
  • You could set the path fixed at your source... But without seeing your source it is difficult to help, if you can change your question and put a snippet of your source from where you want to do this "lock".

  • @Matheus Ribeiro put the excerpt I’m using for this part, thanks for noticing, I really forgot to put the font there. Thanks

1 answer

0


You can validate the path after the person select the file in this way

OpenDialog1.initialDir := 'C:\Seu\caminho\busca\';
SaveDialog1.initialDir := 'C:\Seu\caminho\salvar\';

if(OpenDialog1.Execute)then
begin
  if(ExtractFilePath(OpenDialog1.FileName) = 'C:\Seu\caminho\busca\')then
  begin
    if(SaveDialog1.Execute)then
    begin
      if(ExtractFilePath(SaveDialog1.FileName) <> 'C:\Seu\caminho\salvar\')then
      begin
        idftp1.Put(OpenDialog1.FileName, '/projeto_ftp/banco/' + ExtractFileName(SaveDialog1.FileName));
        // ShowMessage('Transferido');
        idftp1.Get(SaveDialog1.FileName, '/projeto_ftp/' );
      end;
    end;
  end;
end;

In order to be invisible to the customer, you would have to set the paths in the source manually without the option of it being able to select...

An example would be like this:

procedure SeuMetodo();
var
  cCaminhoSalvar: String;
  cCaminhoServidor: String;
  cCaminhoArquivo: String;
begin
  cCaminhoSalvar   := 'C:\Seu\caminho\salvar\';
  cCaminhoServidor := 'servidor\arquivos';
  cCaminhoArquivo  := 'C:\Seu\caminho\busca\arquivoTal.bd'; {Aqui teria que tratar o nome do arquivo, caso exista mais de um na pasta}

  idftp1.Put(cCaminhoArquivo, cCaminhoServidor + ExtractFileName(cCaminhoArquivo));
  // ShowMessage('Transferido');
  idftp1.Get(cCaminhoSalvar, cCaminhoServidor);
end; 

(*Não lembro a ordem correta dos parâmetros do PUT e GET*)

Note: To automate your application, you could create a service for it and within the service use a thread with a counter inside it and then, for example, every 1hr it makes the necessary validations and sends your data.

  • The problem is that I need the client not even know what is happening, preferably running the application in hidden mode on Windows, and with automatic upload, you think this is possible?

  • It took me a while to get back, for reasons of force majeure.... well in Windows Task Scheduler I can run the application in a programmed way, but there is some other way to automate the task???

  • For what is invisible to the customer, you would have to set the paths in the source manually without the option of it being able to select... To automate your application, you could create a service for the same and within the service use a thread with a counter inside it and then, for example, every 1hr it makes the necessary validations and sends your data.

  • When I get time I will research this Thread because I do not know this part.

  • Research well and understand how it works because it’s a bit complicated to work with Threads, as in your case, because you don’t know much.

  • 1

    Yes, Thanks for trying to help me, you gave me some important tips!

  • If the path is fixed you don’t need open/savedialog. just get/put ftp.

  • @Ricardoalvescarvalho That’s what I quoted in my comment, I will modify my answer to be highlighted!

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.