Función Para Mover Un Archivo A La Papelera.


Subject: Función Para Mover Un Archivo A La Papelera.
Hola a todos.
Un compañero del foro pergunto en otro post como mover un archivo a la papelera ya que kill no lo hacia.
Bueno me pareció interesante e hice una pequeña función para hacelo.
Se las dejo aquí.

Public Function FileTrash(strInputPath As String) As Boolean ''Mueve un archivo a la papelera. Requiere que se pase la ruta del archivo y si lo logra mover a la papelera devuelve TRUE y si no lo logra devuelve FALSE.

Dim out As Boolean

out = False

If Exist(strInputPath) Then
If Stat(strInputPath).Type = gb.File Then
Shell "gio trash '" & strInputPath & "'" Wait
If Exist(strInputPath) = False Then
out = True
Endif
Endif
Endif

Return out

End

Saludos.

Profile PM  
Subject: Re: Función Para Mover Un Archivo A La Papelera.
...sin usar Shell:

Library "libgio-2.0"

' GFile * g_file_new_for_path (const char *path)
' Constructs a GFile for a given path.
Private Extern g_file_new_for_path(path As String) As Pointer

' gboolean g_file_trash (GFile *file, GCancellable *cancellable, GError **error)
' Sends file to the "Trashcan".
Private Extern g_file_trash(gfile As Pointer, cancellable As Pointer, gerror As Pointer) As Boolean

' void g_object_unref (gpointer object)
' Decreases the reference count of object.
Private Extern g_object_unref(gobject As Pointer)


Public Sub Main()

Dim s As String
Dim fl As Pointer
Dim bo As Boolean

' Ruta del archivo que queremos mover a la papelera:
s = "/ruta/del/archivo"

fl = g_file_new_for_path(s)

' Mueve el archivo a la papelera:
bo = g_file_trash(fl, 0, 0)
If bo == False Then Error.Raise("Error !")

' Libera la memoria:
g_object_unref(fl)

End

Last edited by vuott on Wednesday, 25 September 2019, 10:58; edited 3 times in total
Profile PM  
Subject: Re: Función Para Mover Un Archivo A La Papelera.
vuott escribió: [Ver mensaje]
...sin usar Shell:...

Vuott, sabes que yo pensé - Esto Vuott seguro que lo hace sin shell - y mira !
Saludos.

Profile PM  
Subject: Re: Función Para Mover Un Archivo A La Papelera.
tincho escribió: [Ver mensaje]
vuott escribió: [Ver mensaje]
...sin usar Shell:...

Vuott, sabes que yo pensé - Esto Vuott seguro que lo hace sin shell - y mira !



Profile PM  
Subject: Re: Función Para Mover Un Archivo A La Papelera.
vuott escribió: [Ver mensaje]
tincho escribió: [Ver mensaje]
vuott escribió: [Ver mensaje]
...sin usar Shell:...

Vuott, sabes que yo pensé - Esto Vuott seguro que lo hace sin shell - y mira !




vuott estas últimamente esplendido como las estrellas.

Profile PM  
Subject: Re: Función Para Mover Un Archivo A La Papelera.
gambafeliz escribió: [Ver mensaje]
..vuott estas últimamente esplendido como las estrellas.

¿Ultimamente? Vuott siempre sale con estas cosas, una mas sorprendente que la otra.
Saludos.

Profile PM  
Subject: Re: Función Para Mover Un Archivo A La Papelera.
tincho escribió: [Ver mensaje]
lo hace sin shell


...pero ahora sin Shell ni sistema GIO:

Public Sub Main()

Dim arch, ruta As String

' El nombre del archivo que queremos mover a la papelera:
arch = "nombre_del_archivo"

' La ruta del archivo + el nombre del archivo:
ruta = "/ruta/del/archivo" &/ arch

' Mueve el archivo a la papelera, identificando la ruta de esta:
Move ruta To User.Home &/ ".local/share/Trash/files" &/ arch

End

Last edited by vuott on Wednesday, 25 September 2019, 11:25; edited 2 times in total
Profile PM  
Subject: Re: Función Para Mover Un Archivo A La Papelera.
vuott escribió: [Ver mensaje]
tincho escribió: [Ver mensaje]
lo hace sin shell


...pero ahora sin Shell ni sistema GIO:

Public Sub Main()

Dim arch, ruta As String

' El nombre del archivo que queremos mover a la papelera:
arch = "nombre_del_archivo"

' La ruta del archivo + el nombre del archivo:
ruta = "/ruta/del/archivo" &/ arch

' Mueve el archivo a la papelera, identificando la ruta de esta:
Move ruta To User.Home &/ ".local/share/Trash/files" &/ arch

End


vuott lo dicho me quito el sombrero. Aunque siempre digo que cuando sea grande quiero ser tu, yo creo que el que vale, vale y el que no pues informático

Profile PM  
Subject: Re: Función Para Mover Un Archivo A La Papelera.
vuott escribió: [Ver mensaje]
tincho escribió: [Ver mensaje]
lo hace sin shell

...pero ahora sin Shell ni sistema GIO:

Que bueno Vuott. mejora continua.
Saludos.

Profile PM  

Page 1 of 1


  
You cannot post new topics
You cannot reply to topics
You cannot edit your posts
You cannot delete your posts
You cannot vote in polls
You cannot attach files
You can download files
You cannot post calendar events

   

This is a "Lo-Fi" version of our main content. To view the full version with more information, formatting and images, please click here.

Powered by Icy Phoenix based on phpBB
Design by DiDiDaDo

Generation Time: 0.2919s (PHP: -63% SQL: 163%)
SQL queries: 25 - Debug Off - GZIP Enabled