Hi all
Ok, ive been trying to work this out for hours but without any luck.
The code below saves the contents of listbox2 to a folder, removes unwanted characters and then shortens the file name length down to 8 characters.
Now, what im trying to do is to put the filenames from listbox2 into a string JPGFILENAMES which will hold the filenames before being modified
(ie. Vista Areo.jpg)
Next, i need to have the modified filenames put into another string JPG (ie VistaAre.jpg)
Now, when all the filenames have been put into each string they would look like this:
JPGFILENAMES(1)="Vista Areo.jpg"
JPG(1)="VistaAre.jpg"
ect..
Or it might be easier to write them to a text file so they would look like:
"Vista Areo.jpg",VistaAre.jpg
ect..
That way i could just read the text file and then write the contents to the target text file when ready.
Regards
Worf
Ok, ive been trying to work this out for hours but without any luck.
The code below saves the contents of listbox2 to a folder, removes unwanted characters and then shortens the file name length down to 8 characters.
Now, what im trying to do is to put the filenames from listbox2 into a string JPGFILENAMES which will hold the filenames before being modified
(ie. Vista Areo.jpg)
Next, i need to have the modified filenames put into another string JPG (ie VistaAre.jpg)
Now, when all the filenames have been put into each string they would look like this:
JPGFILENAMES(1)="Vista Areo.jpg"
JPG(1)="VistaAre.jpg"
ect..
Or it might be easier to write them to a text file so they would look like:
"Vista Areo.jpg",VistaAre.jpg
ect..
That way i could just read the text file and then write the contents to the target text file when ready.
Code:
Try
Copy files from Listbox2 to a Folder.
For Each i As Item In ListBox2.Items
My.Computer.FileSystem.CopyFile(i.Name, Application.StartupPath _
& DataDLL.PAPERTMP + i.Shortname)
Remove Unwanted Characters
Dim fileInfo As FileInfo
For Each fileInfo In New DirectoryInfo(Application.StartupPath & DataDLL.PAPERTMP).GetFiles()
Dim newFileName As String = fileInfo.Name
newFileName = newFileName.Replace("_", String.Empty)
newFileName = newFileName.Replace(" ", String.Empty)
newFileName = newFileName.Replace("-", String.Empty)
newFileName = newFileName.Replace(".jpg", String.Empty)
IO.File.Move(fileInfo.FullName, fileInfo.DirectoryName + "\" + newFileName)
Next
Check Length of Filename And Shorten If Greater Than 8
Dim fileInfo2 As FileInfo
For Each fileInfo2 In New DirectoryInfo(Application.StartupPath & DataDLL.PAPERTMP).GetFiles()
Dim newFileName As String = fileInfo2.Name
If newFileName.Length > 8 Then
IO.File.Move(fileInfo2.FullName, fileInfo2.DirectoryName + "\" + newFileName.Substring(0, 8) & ".jpg")
Else
IO.File.Move(fileInfo2.FullName, fileInfo2.DirectoryName + "\" + newFileName & ".jpg")
End If
Next
Catch ex As Exception
MsgBox(ex.Message)
Exit Sub
End Try
End Select
Regards
Worf