Subscribe for automatic updates: RSS icon RSS

Login icon Sign in for full access | Help icon Help
Advanced search

Pages: [1]
  Reply  |  Print  
Author Topic: Create a directory on the local computer  (Read 260 times)
Jose Edvandro M.
Posts: 3


« on: July 12, 2022, 04:01:25 am »


Goodnight,
I would like to know if there is a way to create a directory on the local computer and then copy a file to that directory created?
Example directory: C:\test\SIN
Stefan S.
Posts: 84


« Reply #1 on: July 12, 2022, 08:44:29 am »

Good Morning,

you can create a  bat and copy this to the Client-PC (fgl_putfile)
Then execute this File on the client.
To execute the Client-File I create a further vbs script, to avoid the popup of the dos-command box

Stefan



Code
  1. #------------------------------------------------------------------------------
  2. function wc_verzeichnis_anlegen(lo_wcdir)
  3. define lo_stm             string,
  4.       lo_clientfile      string,
  5.       lo_clientdir       string,
  6.       lo_clientbatchfile string,
  7.       lo_serverfile      string,
  8.       lo_wcdir           string,   --name des webcomponent-verzeichnis
  9.       lo_z               smallint,
  10.       lo_i               smallint,
  11.       lo_buf             base.StringBuffer,
  12.       lo_ch              base.channel,
  13.       lo_z2              smallint,
  14.       lo_z3              smallint
  15.  
  16.   call ui.interface.frontcall("standard", "feinfo", ["datadirectory"],[lo_clientfile])
  17.   let lo_clientdir = lo_clientfile
  18.  
  19.   --batchdatei für mkdir
  20.   let lo_serverfile = "/programme/lutztmp/anlegen_", gl_vlogin clipped, ".bat"
  21.   let lo_ch = base.channel.create()
  22.   call lo_ch.openfile(lo_serverfile, "w")
  23.   call lo_ch.setdelimiter("")
  24.   let lo_clientfile = lo_clientdir clipped, "\\anlegen.bat"
  25.   let lo_stm = "mkdir ", "\"", lo_clientdir clipped, "\\", lo_wcdir clipped, "\""
  26.   call lo_ch.write(lo_stm)
  27.   call lo_ch.write(ascii 13)
  28.   call lo_ch.close()
  29.   call datei_auf_client_maps(lo_serverfile, "X")  returning lo_clientbatchfile --nur ablegen, nicht ausführen
  30.  
  31.   --dieses VB-Script wird ausgeführt. Das verhindert das Aufpoppen der DOS-Box
  32.   let lo_serverfile = "/programme/lutztmp/ausfuehren_", gl_vlogin clipped, ".vbs"
  33.   let lo_ch = base.channel.create()
  34.   call lo_ch.openfile(lo_serverfile, "w")
  35.   call lo_ch.setdelimiter("")
  36.   call lo_ch.write("Set WshShell = WScript.CreateObject(\"WScript.Shell\")")
  37.   let lo_clientbatchfile = "\"", "\"", lo_clientbatchfile clipped, "\"", "\""   --es müssen drei vorher und nachher sein !
  38.  
  39.   let lo_stm = "WshShell.Run ", lo_clientbatchfile clipped, ",0,True"
  40.   call lo_ch.write(lo_stm)
  41.   call lo_ch.close()
  42.   call datei_auf_client_maps(lo_serverfile, "A")  returning lo_clientbatchfile
  43.  
  44. end function
  45. #--------------------------------------------------------------------------------------------------
  46.  


Code
  1. #------------------------------------------------------------------------------
  2. function datei_auf_client_maps(lo_serverfile, lo_aktion)
  3. define lo_serverfile   string,  #pfad + Name der ServerDatei,
  4.       lo_clientfile   string,  #
  5.       lo_datei        string,  #Name des lo_serverfile, ohne Verzeichnis
  6.       lo_datei2       string,  #Name des lo_serverfile, ohne Verzeichnis + currentstempel
  7.       lo_time         string,
  8.       lo_aktion       char(1)  ##A=ausführen (pdf wird angezeigt, vbs ausgeführt), K=nur auf client
  9.                                ##X=Datei ohne Zeitstempel ablegen, aber nicht ausführen!
  10.  
  11.   let lo_serverfile = lo_serverfile clipped
  12.   if os.path.isfile(lo_serverfile) = false then
  13.      error   "......Datei nicht auf dem Server ...."
  14.      return  --keine Anzeige
  15.   end if
  16.  
  17.   --call set_current() returning lo_time
  18.  
  19.   call ui.interface.frontcall("standard", "feinfo", ["datadirectory"],[lo_clientfile])
  20.  
  21.   if lo_aktion = "X" then   --kein Zeitstempel!
  22.      let lo_datei  = os.path.basename(lo_serverfile)
  23.      let lo_datei2 = lo_datei
  24.      let lo_clientfile = lo_clientfile clipped, "\\", lo_datei2
  25.   else
  26.      let lo_datei  = os.path.basename(lo_serverfile)
  27.      let lo_datei2 = os.path.rootname(lo_datei) clipped, "_", lo_time clipped, ".",
  28.                                                               os.path.extension(lo_datei clipped)
  29.      let lo_clientfile = lo_clientfile clipped, "\\", lo_datei2
  30.   end if
  31.  
  32.   try
  33.      call fgl_putfile(lo_serverfile, lo_clientfile)
  34.   end try
  35.  
  36.   let lo_clientfile = "\"", lo_clientfile clipped, "\""
  37.   if lo_aktion = "A" then   --anzeigen, oder ausführen
  38.      call ui.Interface.frontCall("standard", "shellexec", [lo_clientfile clipped], [])
  39.   else
  40.      --nix, wird nur auf client kopiert
  41.   end if
  42.  
  43.   return lo_clientfile
  44.  
  45. end function
  46. #------------------------------------------------------------------------------
  47.  

Gary C.
Posts: 102


« Reply #2 on: July 12, 2022, 09:02:49 am »

Hello

This is how we do this using GDC as the client and exploiting front calls:

Code
  1.  
  2. # Use a frontcall to get the base directory from the local environment variable
  3. # Then build a string holding the target directory using the relevant path separator and directory, in our case the ID of the MDI container
  4. # Then build and execute the relevant local command
  5.  
  6.    if g_clientOperatingSystem = "LINUX" then
  7.        call ui.interface.frontCall("standard", "getenv", "HOME", g_tmpClientDir)
  8.  
  9.        let g_tmpClientDir = g_tmpClientDir.append(g_ClientPathSeparator||g_container)
  10.        let sCmd = "mkdir "||g_tmpClientDir
  11.        call ui.Interface.frontCall("standard", "execute", [sCmd, 1], [])
  12.    else
  13.        call ui.interface.frontCall("standard", "getenv", "LOCALAPPDATA", g_tmpClientDir)
  14.  
  15.        let g_tmpClientDir = g_tmpClientDir.append(g_ClientPathSeparator||g_container)
  16.        let sCmd = "cmd.exe /C \"mkdir ", g_tmpClientDir, "\""
  17.        call ui.Interface.frontCall("standard", "execute", [sCmd, 1], [])
  18.    end if
  19.  

Then to clean up after the application finishes we use this:

Code
  1.    if g_clientOperatingSystem = "LINUX" then
  2.        let sCmd = "rm -fr ", g_tmpClientDir
  3.        call ui.Interface.frontCall("standard", "execute", [sCmd, 1], [])
  4.    else
  5.        let sCmd = "cmd.exe /C \"rmdir /S /Q ", g_tmpClientDir, "\""
  6.        call ui.Interface.frontCall("standard", "execute", [sCmd, 1], [])
  7.    end if
  8.  

To copy a file to the local directory we use fgl_putfile in a fashion like this:

Code
  1.  
  2. # We stop the standard error handling and build the path to the destination file
  3. # We then use fgl_putfile and check for any issue before resuming normal error handling
  4.  
  5.    whenever error continue
  6.  
  7.    let sFileDestination = g_tmpClientDir.trim(), g_ClientPathSeparator.trim(), p_documentR.documentname
  8.    call fgl_putfile(sFileSource, sFileDestination)
  9.    if status then
  10.        call sys_showMessage("Error", "Unable to download file: "||sFileSource||"||CRLF||To: "||sFileDestination, "")
  11.        whenever error call sys_errorHandler
  12.        return
  13.    end if
  14.  
  15.    whenever error call sys_errorHandler
  16.  

Hope that helps.

Gary
Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.21 | SMF © 2015, Simple Machines