Solved

Rename a directory that contains a file

Posted on 2014-10-08
6
112 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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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 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…
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…

773 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