Ok so I have about 12,000 files that I have in a list box (well many lsit boxes but if I find the right code for one it will work for them all)
Anyways, here's what the program does. I have a folders contents being called into a list box. Some files have this annoying little mark at the end of them which is (U) and (U) [!]. I dont want these to be shown within the list box.
Can I either
1) Write a program that goes through each files and renames each file what it is minus (U) like If File has (U) delete (U)
or
2) Hide the (U) within the list box somehow?
This is completely boggling my mind and google for that matter, please help!
u can use replace() replace the "(U)" or "(U) [!]" with " ", but u should check the character position first and see if the file contains that character at the end
Renaming the files and deleting parts of the names within your listbox only are two pairs of shoes.
These [xxx] or (nnn) parts usually are there for some reason: if there is already a file named image.jpg and e.g. the IE wants to create a new file with the same name in the same (temporary) folder, it creates image[1].jpg
In most cases you won't be able to rename image[1].jpg to image.jpg, because the filename would yhen be duplicate, so the renaming will be denied.
Nevertheless you can certainly make a loop and go through the names of your listbox to remove unwanted name parts, but you must be aware, that this might produce duplicate names in the list, where an unambiguous relation to the original file is no longer given.
Removal of character sequences can be done by several means. Regular expressions might come to mind, but also a conventional algorithm can be implemented.
This little sample would remove all parts in square brackets from a name, be it [001] or [U] or [x01]:
I simply put a listbox List and button Command1 on my form to show how it works.
Code:
Private Sub Command1_Click()
Dim i%, n%, m%, a$, b$
For i = 0 To List1.ListCount - 1
Do
n = InStr(List1.List(i), "[")
If n Then
m = InStr(n, List1.List(i), "]")
If m Then
If n > 1 Then a$ = Left$(List1.List(i), n - 1) Else a$ = ""
If m < Len(List1.List(i)) Then b$ = Mid$(List1.List(i), m + 1) Else b$ = ""
List1.List(i) = a$ + b$
End If
End If
Loop Until n = 0 Or m = 0
Next
End Sub
Private Sub Form_Load()
With List1
.AddItem "Name[001].xxx"
.AddItem "name[U].xxz"
.AddItem "[234]name.dot"
.AddItem "name[001]"
.AddItem "name[1][2].end"
.AddItem "[xxx]"
End With
End Sub
Note that names like "[xxx]" or "[1][12]" will result in being deleted completely.
Bookmarks