Author Topic: Search for backup directory  (Read 1736 times)

0 Members and 1 Guest are viewing this topic.

Marco Jacinto

  • Newt
  • Posts: 47
Search for backup directory
« on: February 17, 2015, 02:05:52 PM »
Hi to everybody, I don't post a lot over here, but read you every day and have learned a lot, thanks for all the support.

I'm working in a project to backup some directory into a another one that is two or three leves under, so far I have created a solution in lisp, but I want to create a script that allows me to right click any directory or file in Windows Explorer, then check for the backup repository path, I already made some progress using the power shell but I can't figure out why it doesn't give me the right path.

Thanks in advance

This is the lisp

Code: [Select]
(setq RutaArchivos
    "M:\\20150115 Proceso\\20150118 PROPUESTA CARPETAS\\NOMBREPROYECTO_AÑOMESDIA\\03-EJECUTIVO\\14-ILUMINACION"
      TextoABuscar "X-ENTREGAS"
)
(BuscaEntrega RutaArchivos TextoABuscar)

(defun BuscaEntrega (RutaArchivos TextoABuscar)
  (cond
    ((eq (strlen RutaArchivos) 3)nil) ;_Se toma en consideracion que la ruta
     ;_llego a la raiz c:\ o similar
    ((not (member TextoABuscar
  (VL-DIRECTORY-FILES RutaArchivos "*" -1)
  )
     )
     (BuscaEntrega (VL-FILENAME-DIRECTORY RutaArchivos) TextoABuscar)
    )
    (T (strcat RutaArchivos "\\" TextoABuscar))
  )
)

And the powershell script
Code: [Select]
function Get-Entregas ($Path,$CadenaaBuscar)
     {
     if (-not(test-path $Path)) {Write-host " "}
        elseif (-not @(get-childitem $Path -filter $CadenaaBuscar))
           {Get-Entregas (split-path $Path)}
        else
           {
            $NuevoDirectorio = $Path + '\' + $CadenaaBuscar           
           }
           write-host $NuevoDirectorio
    }
 
Get-Entregas $Path

Lee Mac

  • Seagull
  • Posts: 12921
  • London, England
Re: Search for backup directory
« Reply #1 on: February 17, 2015, 05:07:46 PM »
Another way to write it:

LISP:
Code - Auto/Visual Lisp: [Select]
  1. (defun getpath ( root fold )
  2.     (setq root (vl-string-right-trim "\\" (vl-string-translate "/" "\\" root)))
  3.     (cond
  4.         (   (< (strlen root) 3) nil)
  5.         (   (findfile (strcat root "\\" fold)))
  6.         (   (getpath (vl-filename-directory root) fold))
  7.     )
  8. )
Code - Auto/Visual Lisp: [Select]
  1. (getpath "M:\\20150115 Proceso\\20150118 PROPUESTA CARPETAS\\NOMBREPROYECTO_AÑOMESDIA\\03-EJECUTIVO\\14-ILUMINACION" "X-ENTREGAS")

PowerShell:
Code - PowerShell: [Select]
  1. function getpath ( [string]$root, [string]$fold )
  2. {
  3.     $root = ($root -replace '/','\').TrimEnd('\')
  4.     if ($root.Length -gt 2)
  5.     {
  6.         if (test-path($root + '\' + $fold))
  7.         {
  8.             $root + '\' + $fold
  9.         }
  10.         else
  11.         {
  12.             getpath (split-path $root -parent) $fold
  13.         }
  14.     }
  15. }
Code - PowerShell: [Select]
  1. getpath 'M:\20150115 Proceso\20150118 PROPUESTA CARPETAS\NOMBREPROYECTO_AÑOMESDIA\03-EJECUTIVO\14-ILUMINACION' 'X-ENTREGAS'

Marco Jacinto

  • Newt
  • Posts: 47
Re: Search for backup directory
« Reply #2 on: February 17, 2015, 06:08:11 PM »
Excelent Lee, will try to study a lot more to make awesome thigs like you do  :lmao:

Saludos
Marco Jacinto

Lee Mac

  • Seagull
  • Posts: 12921
  • London, England
Re: Search for backup directory
« Reply #3 on: February 17, 2015, 06:54:22 PM »
Thank you Marco :-)