Solved

Rename a directory that contains a file

Posted on 2014-10-08
6
114 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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