|
-
Feb 10th, 2008, 08:39 AM
#1
Thread Starter
Frenzied Member
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
-
Feb 10th, 2008, 09:00 AM
#2
Frenzied Member
Re: rename the folder name contains empty space folder
Use Replace Function
 Originally Posted by MSDN
Replace(expression, find, replace[, start[, count[, compare]]])
So to remove the empty spaces:
Code:
MsgBox = Replace("TKSSBLOCK C", " ", "")
-
Feb 10th, 2008, 09:08 AM
#3
Thread Starter
Frenzied Member
Re: rename the folder name contains empty space folder
 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", " ", "")[/
-
Feb 10th, 2008, 09:38 AM
#4
Frenzied Member
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.
-
Feb 10th, 2008, 12:37 PM
#5
Hyperactive Member
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.
-
Feb 10th, 2008, 07:14 PM
#6
Thread Starter
Frenzied Member
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.
-
Feb 10th, 2008, 07:46 PM
#7
Thread Starter
Frenzied Member
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.
-
Feb 10th, 2008, 09:13 PM
#8
Frenzied Member
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.
-
Feb 10th, 2008, 09:31 PM
#9
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.
-
Feb 11th, 2008, 12:34 AM
#10
Thread Starter
Frenzied Member
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.
-
Feb 11th, 2008, 08:58 AM
#11
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.
-
Feb 11th, 2008, 09:57 AM
#12
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:
Private Declare Function GetShortPathName Lib "kernel32.dll" Alias "GetShortPathNameA" ( _
ByVal lpszLongPath As String, _
ByVal lpszShortPath As String, _
ByVal cchBuffer As Long _
) As Long
Public Function ShortPath(ByVal sLongPath As String) As String
Const MAX_PATH As Long = 260&
Dim sShortPath As String
Dim nLen As Long
sShortPath = String(MAX_PATH, vbNullChar)
nLen = GetShortPathName(sLongPath, sShortPath, MAX_PATH)
ShortPath = Left(sShortPath, nLen)
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|