Moving all files within a folder to another specified folder

Moving all files within a folder to another specified folder

Daan_M
Collaborator Collaborator
168 Views
1 Reply
Message 1 of 2

Moving all files within a folder to another specified folder

Daan_M
Collaborator
Collaborator

Hi,

 

I have directory A, with 100 .iam files and 100 .ipt files.

i want to create a new directory '\Output', inside directory A, and move all .ipt files to that folder.

 

I got this far, but i'm not sure how to get the full path of the files, it doesn't show up in the intelliSense;

 

 

Dim OutputFolder = IO.Directory.CreateDirectory(sPathFolder & "\Outputs")
	
Dim AllPartFiles() As String = IO.Directory.GetFiles(sPathFolder & "\", "*.ipt")

For Each PartFile In AllPartFiles

  Dim Source As String =   PartFile. '??? get full path	
  Dim Destination As String = OutputFolder.FullName
  IO.File.Move(Source, Destination)	
	
Next

 

 

If there's better ways to do this feel free to suggest 🙂

0 Likes
Accepted solutions (1)
169 Views
1 Reply
Reply (1)
Message 2 of 2

Andrii_Humeniuk
Advisor
Advisor
Accepted solution

Hi @Daan_M . Please try this code:

Dim OutputFolder As IO.DirectoryInfo = IO.Directory.CreateDirectory(sPathFolder & "\Outputs")
	
Dim AllPartFiles() As String = IO.Directory.GetFiles(sPathFolder & "\", "*.ipt")

For Each PartFile As String In AllPartFiles
	Dim Destination As String = OutputFolder.FullName & "\" & IO.Path.GetFileName(PartFile)
	IO.File.Move(PartFile, Destination)	
Next

 

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature