Results 1 to 12 of 12

Thread: rename the folder name contains empty space folder

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    rename the folder name contains empty space folder

    I have problem here. I use Drivelistbox and filelistbox. If I click the file inside the folder that contains empty space in its folder name, How I can rename the folder?

    Like this, If I select the file inside this folder, How I can rename TKSSBlock C to this TKSSBLOCKC ?
    Code:
    C:\Database\BOUNDARIES\TKSSBlock C\ZONE
    Code:
     If InStr(1, Dir1.Path, " ") > 0 Then
         MsgBox "Pastikan tidak terdapat ruang kosong pada folder, sila buat penamaan semula.", vbExclamation, "Penamaan folder"
         Exit Sub

  2. #2
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: rename the folder name contains empty space folder

    Use Replace Function

    Quote Originally Posted by MSDN
    Replace(expression, find, replace[, start[, count[, compare]]])
    So to remove the empty spaces:
    Code:
    MsgBox = Replace("TKSSBLOCK C", " ", "")
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: rename the folder name contains empty space folder

    Quote Originally Posted by aikidokid
    Use Replace Function



    So to remove the empty spaces:
    Code:
    MsgBox = Replace(dir1, " ", "")
    Thank you, But I the folder name "TKSSBLOCK C" always changes depending on how it the folder was named. How to find any folder name contains empty space in its folder name, it replace the name using this code MsgBox = Replace("TKSSBLOCK C", " ", "")[/

  4. #4
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: rename the folder name contains empty space folder

    To find out if there are any empty spaces in a string use this:

    Code:
    InStr(1, Dir1, " ")
    InStr function
    InStr([start as number], phrase as String, searchstring as String [, compare as integer])

    Instr returns a variant of subtype long specifying the character position of the first occurrence of searchstring in string. The first character position of a string is 1, not 0. InStr returns 0 if string is zero-length, searchstring is not found or start is past any occurrence of searchstring. InStr returns Null if either string or searchstring are Null. InStr returns start if searchstring is zero-length.

    start is an optional argument that specifies the character position where searching for substring in string should begin. The default is 1, referring to the first character in string.

    This link is a good starting point for working with strings.
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  5. #5
    Hyperactive Member
    Join Date
    Aug 2006
    Location
    TeXaS
    Posts
    497

    Re: rename the folder name contains empty space folder

    Im not sure how far you are going with this code. If you are actually renaming the Folders themselves then you may want to be careful renaming them. im sure if your taking out spaces from them, then im pretty sure you are not the one creating that folder to begin with. Many folders that are created from install packages are usually linked in the registry or a database. renaming them could cause issues.

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: rename the folder name contains empty space folder

    Code:
    If InStr(1, Dir1.Path, " ") > 0 Then
         MsgBox "Pastikan tidak terdapat ruang kosong pada folder, sila buat penamaan semula.", vbExclamation, "Penamaan folder"
         Exit Sub
    I used this code and I found that the folder name contains empty space. But I don't know which text that contains empty space. How to get the text contains empty space and then replace it using this code
    Code:
    MsgBox  Replace(dir1, " ", "")
    Last edited by matrik02; Feb 10th, 2008 at 07:52 PM.

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: rename the folder name contains empty space folder

    when I used msgbox Replace(Dir1, " ", ""), the folder name change in the messagebox but when I check
    the folder name in my computer, It does not change permenently when I used this code?nothing happend to change the folder name . How to change the folder name permenently in my computer?
    Last edited by matrik02; Feb 10th, 2008 at 07:53 PM.

  8. #8
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: rename the folder name contains empty space folder

    You didn't say you wanted to change the name permanently.
    I would take note of the comments made by Billy Connor before you do this

    I don't have VB on this machine at work, but to change the name permanently you would use the Name Function.
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  9. #9
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: rename the folder name contains empty space folder

    to prevent you from major computing issues, why would you want to do this? For example, if you rename the "program files" folder with no space, you break every installed program. If you have some reason for not wanting the spaces, what are they? You can enclose any path in quotes and it preserves spaces. for example: "c:\program files". Also in this example, don't forget that every path on your hard drive ALREADY contains a version of the path for DOS to use. For example: Program Files will have the 8.3 filename format of progra~1

    So i ask AGAIN: WHY DO YOU WANT TO DO THIS? There are numerous reasons to NOT do it, and a few workarounds preventing you from ever needing to do it in the first place.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  10. #10

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: rename the folder name contains empty space folder

    Actually it not involved the program files.. I just want to rename my database folder only because some of my data store in C:\Database cannot read the files contains empty space. In the database folder, I have many directory..After I made the change in its folder name, I want to change it back to the original name.. I just want to rename the folder contains empty name for example "Blok C" to "blokC" and change it back after reading the files. Just to read the data only.

  11. #11
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: rename the folder name contains empty space folder

    tell the database the dos8.3 version of the file path. They don't have spaces.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  12. #12
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: rename the folder name contains empty space folder

    I agree with Lord Orwell, if you can't use long filenames use the short 8.3 version of it. Here's some code that will help you getting the 8.3 path:
    vb Code:
    1. Private Declare Function GetShortPathName Lib "kernel32.dll" Alias "GetShortPathNameA" ( _
    2.     ByVal lpszLongPath As String, _
    3.     ByVal lpszShortPath As String, _
    4.     ByVal cchBuffer As Long _
    5. ) As Long
    6.  
    7. Public Function ShortPath(ByVal sLongPath As String) As String
    8.     Const MAX_PATH As Long = 260&
    9.     Dim sShortPath As String
    10.     Dim nLen As Long
    11.    
    12.     sShortPath = String(MAX_PATH, vbNullChar)
    13.     nLen = GetShortPathName(sLongPath, sShortPath, MAX_PATH)
    14.     ShortPath = Left(sShortPath, nLen)
    15. End Function

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width