Solved

Rename a directory that contains a file

Posted on 2014-10-08
6
113 Views
Last Modified: 2014-10-08
Rename a directory that contains a file
old directory
C:\Documents and Settings\All Users.WINDOWS\Documents\RoofCalculator\Bryant 4587 lotta way\flooring bids\Bids.dat
I am trying to remove replace this directory name, but copy the values of Bids.dat to the new directory

New name
C:\Documents and Settings\All Users.WINDOWS\Documents\RoofCalculator\Bryant 4587 lotta way\Floor Repair bids\Bids.dat
how to do this?
0
Comment
Question by:isnoend2001
  • 3
  • 2
6 Comments
 
LVL 12

Expert Comment

by:jkaios
ID: 40369554
There are several ways to do it.  If you're using the VB6, then the quickiest and simplies way to do it is to use the intrinsic function/statement.

Private Sub Form_Click()
   Name "C:\Documents and Settings\All Users.WINDOWS\Documents\RoofCalculator\Bryant 4587 lotta way\flooring bids" As _
               "C:\Documents and Settings\All Users.WINDOWS\Documents\RoofCalculator\Bryant 4587 lotta way\Floor Repair bids"
End Sub

Open in new window

0
 
LVL 15

Expert Comment

by:ChloesDad
ID: 40369574
If you just want to rename one folder to another then use the name command

     Name strSource As strTarget     (As jKaios stated, he beat me to it :))

where strsource is the original folder name and strtarget is the new folder name (that must not exist) if it already exists then it must be deleted first.

If you just want to move a file then the folder path in the strTarget must exist.
0
 

Author Comment

by:isnoend2001
ID: 40369612
thanks have already tried that eg:
Dim OldFileName As String
Dim NewFileName As String


OldFileName = "C:\Documents and Settings\All Users.WINDOWS\Documents\RoofCalculator\Bryant 4587 lotta way\flooring bids\Bids.dat"
NewFileName = "C:\Documents and Settings\All Users.WINDOWS\Documents\RoofCalculator\Bryant 4587 lotta way\Floor Repair bids\Bids.dat"
Name OldFileName As NewFileName 'error file not found
I want to keep the value of Bids.dat
I think the file under the last folder causes the problem
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 12

Accepted Solution

by:
jkaios earned 500 total points
ID: 40369621
Since you're trying to rename just the DIRECTORY and NOT the FILE, you shouldn't include the filename.  Try the following (note that the "Bids.dat" file is NOT included in the strings).

OldFileName = "C:\Documents and Settings\All Users.WINDOWS\Documents\RoofCalculator\Bryant 4587 lotta way\flooring bids"
NewFileName = "C:\Documents and Settings\All Users.WINDOWS\Documents\RoofCalculator\Bryant 4587 lotta way\Floor Repair bids"

Name OldFileName As NewFileName

Open in new window

0
 

Author Closing Comment

by:isnoend2001
ID: 40369679
Thanks jkaios that is better than what i was thinking i would have to resort to:
copy the file
kill the file
remove the directory
save the file and new directory
0
 
LVL 12

Expert Comment

by:jkaios
ID: 40369713
Always a pleasure.  Very glad to be of assistance, especially to hear that it worked :-)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question