Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi all

 

Ok, i've 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.

 

 

 

 


    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

  • Administrators
Posted

You might want to look at http://www.pinvoke.net/default.aspx/kernel32/GetShortPathName.html as a way of getting a file's 8.3 name as simply truncating to 8 characters will fail if you have many files with the same starting name.

 

Have you looked at the StreamWriter class? This should allow you to write a text file with minimal effort.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...