iLogic Delete Files containing string Value

iLogic Delete Files containing string Value

jam_bhatti
Enthusiast Enthusiast
1,909 Views
11 Replies
Message 1 of 12

iLogic Delete Files containing string Value

jam_bhatti
Enthusiast
Enthusiast

Hi,

 

I am trying to delete files containing similar words in files. in my case NN as perameter value and exist in all files as mentioned in below list.

 

"Nozzle-01_" & NN & ".iam"
"Nozzle Neck-01-01_" & NN & ".ipt"
"NozzleRepad-01-01_" & NN & ".ipt"
"Flange-01-01_" & NN & ".ipt"
"Blind-01-01_" & NN & ".ipt"
"Gasket-01-01_" & NN & ".ipt"

 

found some way and applied but un-successful.

if someone help me it will be highly appreciated.

Thanks in advance

 

SyntaxEditor Code Snippet

Dim iPath As String = ThisDoc.Path & "\"
Dim ContainingFileName As String = NN
If IO.File.Exists(iPath.Contains(ContainingFileName)) Then
    IO.File.Delete(ContainingFileName)
End If

 

 

 

 

 

 

 

 

0 Likes
Accepted solutions (2)
1,910 Views
11 Replies
Replies (11)
Message 2 of 12

MechMachineMan
Advisor
Advisor

Google: Msdn + vb.net + delete files.

 

 

Good luck.


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 3 of 12

jam_bhatti
Enthusiast
Enthusiast

 

HI,

@MechMachineMan

 

Thanks for your reply i think every one first putting query on google to find solution and then post to the forum.

and i am still did't find solutiion from google (MSDN) or may be unable to compile them with my porblem. i hope you will help with some code snippets.

 

Thanks

 

 

0 Likes
Message 4 of 12

MechMachineMan
Advisor
Advisor
1) ThisDoc.Path only gets you the path of the folder the file is in, not the folder. Use

ThisApplication.ActiveDocument.FullFileName instead.

If you get errors, plz post screenshots of them so that we can help debug without having to recreate the program/documents

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 5 of 12

jam_bhatti
Enthusiast
Enthusiast

HI,

 

Nothing happened, close rule without any error. file still exist in the folder.Smiley Sad

 

SyntaxEditor Code Snippet

Dim iPath As String = ThisApplication.ActiveDocument.FullFileName
Dim ContainingFileName As String = NN
If System.IO.File.Exists(iPath.Contains(ContainingFileName)) Then
    System.IO.File.Delete(ContainingFileName)
End If

 

0 Likes
Message 6 of 12

MechMachineMan
Advisor
Advisor

How you currently have it written, it will only delete the file you have open in inventor if it's name has NN. Seeing as the file is in use, it is probably not allowing you to delete it. 


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 7 of 12

jam_bhatti
Enthusiast
Enthusiast

as my first post the folder exist many files containg file name "NN" which i define when created the parts or assemblies. the same way i want to delete them which file names are containing or having names with "NN".

 

File name are show below

 

"Nozzle-01_" & NN & ".iam"
"Nozzle Neck-01-01_" & NN & ".ipt"
"NozzleRepad-01-01_" & NN & ".ipt"
"Flange-01-01_" & NN & ".ipt"
"Blind-01-01_" & NN & ".ipt"
"Gasket-01-01_" & NN & ".ipt"

 

 

so please correct me to meet my requirements.

 

 

0 Likes
Message 8 of 12

MechMachineMan
Advisor
Advisor

Dim oFile As String

Dim oFiles As String()

 

oFiles = System.IO.Directory.GetFiles(oFolder)

 

For Each oFile In oFiles

       '

       '

       '

Next


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 9 of 12

GeorgK
Advisor
Advisor
Accepted solution

Maybe like this:

 

For Each foundFile As String In My.Computer.FileSystem.GetFiles(
    My.Computer.FileSystem.SpecialDirectories.MyDocuments,
    Microsoft.VisualBasic.FileIO.SearchOption.SearchAllSubDirectories, "*.ipt")

    Listbox1.Items.Add(foundFile)
Next
Message 10 of 12

MechMachineMan
Advisor
Advisor

You could also try something like:

 

https://msdn.microsoft.com/en-us/library/ms143316(v=vs.110).aspx

 

 

System.IO.Directory.GetFiles ( _
	path As String, _
	searchPattern As String, _
	searchOption As SearchOption _
) As String()
Parameters path Type: System.String

The relative or absolute path to the directory to search. This string is not case-sensitive.

 

searchPattern Type: System.String

The search string to match against the names of files in path. This parameter can contain a combination of valid literal path and wildcard (* and ?) characters (see Remarks), but doesn't support regular expressions.

 

searchOption Type: System.IO.SearchOption

One of the enumeration values that specifies whether the search operation should include all subdirectories or only the current directory.


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 11 of 12

xiaodong_liang
Autodesk Support
Autodesk Support
Hi jam_bhatti,

It looks to me some of the replies from the gurus have helped this question,
but it seems you assigned NN to ContainingFileName without the quotation mark? I think it should be:

Dim ContainingFileName As String = "NN"

Are you still having the problem? If no, could you mark the one who helped you as a solution? thank you.
Message 12 of 12

jam_bhatti
Enthusiast
Enthusiast
Accepted solution

Thanks to all

finally i get the solution as quoted

 

'Delete Files from folder containing NN
Dim path As String = ThisDoc.Path & "\"
For Each foundFile As String In My.Computer.FileSystem.GetFiles(path,
Microsoft.VisualBasic.FileIO.SearchOption.SearchAllSubDirectories, "*" & NN & ".*")
My.Computer.FileSystem.DeleteFile(foundFile)
Next 

 

0 Likes