Solved

Rename a directory that contains a file

Posted on 2014-10-08
6
109 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now