Delete, move and move and delete from one folder to a new one.

Delete, move and move and delete from one folder to a new one.

CCarreiras
Mentor Mentor
638 Views
1 Reply
Message 1 of 2

Delete, move and move and delete from one folder to a new one.

CCarreiras
Mentor
Mentor

HI!

 

I found some peaces of code, and i believe is possible to do what i need.

 

I need something like that:

 

I have already folders, where I save files converted from Inventor dwg to pdf and dwg acad and dxf

workspace &”\dxf”

workspace &”\dwg”

This work fine.

 

 

What I need is.

When I create a new parametrization, to have the possibility to fire a rule (clicking in a button in a form for ex.), to ask the user what to do with previous files in that folders (if they exist)… delete, move to a new folder, or move and delete.

In case "move (like copy/paste) or move and delete (like cut/paste)" asking for destination folder and create that folder is a good feature...

For now, after any new parametrization, the user must remember that have to clean the folders after create new pdf or dwg.

 

 

Something like this_________check if exist files in folder and what tro do with them

 

Try
		If System.IO.File.Exists(aExist) = True Then
			Select Case UCase(Action)
			Case "D"
				System.IO.File.Delete(oLocation)
			Case "M"
				System.IO.File.Move(aExist, oLocation)
			Case "DM"
				System.IO.File.Delete(oLocation)
				System.IO.File.Move(aExist, oLocation)
			End Select
		End If

 

More this__________Ask for a folder and save  it in the new folder. 

 

Imports System
Imports System.Diagnostics
Imports System.Threading
Imports System.Windows.Forms

Sub Main()
oFolder = oFolderDlg

r= MsgBox(oFolder & " was selected" &vbLf & vbLf & "Proceed?", MsgBoxStyle.YesNo,"iLogic")
If r = MsgBoxResult.No
Exit Sub
End If

 

 

Thank you.

CCarreiras

EESignature

0 Likes
639 Views
1 Reply
Reply (1)
Message 2 of 2

rossano_praderi
Collaborator
Collaborator

Hi Carlos,

I would like to give you a starting code for your request

 

 

Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports System.IO

Sub Main
		'MultiValue.SetList("Choice", "Delete", "Move", "Move/Delete")
	Choice = InputListBox("Prompt", MultiValue.List("Choice"), Choice, Title := "Title", ListName := "List") ' Choice is an user parameter
	
	Select Case Choice
		Case "Delete"
			' your code here
		Case "Move"
			' your code here
		Case "Move/Delete"
			' your code here
	End Select
	MsgBox(fBrowser)
End Sub

Private Sub OnAllFiles(Action As String, sourceDir As String, DestDir As String)
Try
	Dim FileList As String() = System.IO.Directory.GetFiles(sourceDir, "*.*")
	DestDir = fBrowser()
	
	Select Case Action
		Case "D"
			For Each f As String In FileList
				System.IO.File.Delete(f)
			Next
		Case "M"
			For Each f As String In FileList
				System.IO.File.Move(f, DestDir)
			Next
	End Select
					
Catch dirNotFound As DirectoryNotFoundException
	MsgBox(dirNotFound.Message)
End Try									
End Sub

Private Function fBrowser() As String
Dim nDialog as New FolderBrowserDialog
Dim result As DialogResult = nDialog.ShowDialog()
     If ( result = DialogResult.OK  And nDialog.SelectedPath IsNot Nothing) Then
		fBrowser = nDialog.SelectedPath
	Else
		fBrowser = "NO FOLDER SELECTED"
	End If
End Function

 

Bregs

Rossano Praderi



--------------------------------------
If my post answers your question, please click the "Accept as Solution"
button. This helps everyone find answers more quickly!
---------------
0 Likes