Rename folder and file (1 Viewer)

guestbb

Registered User.
Local time
Today, 12:30
Joined
Jul 14, 2015
Messages
44
I have a form where users add pictures using folder creating and placing pictures in those folders. Folder and file names are based of textboxes in the form.
For editing I made a form where they can change data in those textboxes and update the folder and file names.
I wrote code for this but when I run it i get Run-time error '53': File not found.
The file location is correct but I think the problem is renaming folders, but I dont have the solution.

To explain the code.
The GetLink1 creates a part of a full (the folder naming part) link to the image. It uses data from the textboxes to make it. This here creates the new part of the link with new changes made in textboxes.
LinkVo adds the location of the database to the new updated link.
GetPic1 creates the new name of the picture.
GetFullPic1 is the full link of the new names of folders and picture.
OldLink1 contains the old full link of the folders and links (TxtUrlPic1 is a textbox that contains the part of the old link).

I used Name function to try to change the folder and file names but I get this error above. I checked with ?OldLink1 and ?GetFullPic1. The links are correct but it doesnt want to rename. Any ideas?

Code:
    Dim GetLink1 As String
    Dim LinkVo As String
    Dim GetPic1  As String
    Dim GetFullPic1   As String
    Dim OldLink1 As String
    
    If IsNull(MarkVeh & ModVeh & TipMot) Then
    Exit Sub
    End If
    
    GetLink1 = "\BASE DATAS\" & MarkVeh & "\" & ModVeh & " " & TipMot & " - " & VlasVeh & " " & TelMob & " (" & KorVoz & " - " & KorTelMob & ")"
          
    LinkVo = CurrentProject.Path & GetLink1
    
    OldLink1 = CurrentProject.Path & Me.TxtUrlPic1.Value
    

    GetPic1  = "\" & MarkVeh & " " & ModVeh & " " & TipMot & " - " & VlasVeh & " (" & KorVoz & ")(1).jpg"
    GetFullPic1   = LinkVo & GetPic1 
    
    If IsNull(TxtUrlPic1) Then
        Exit Sub
    End If
    
    If GetFullPic1   = OldLink1 Then
    Exit Sub
    Else
    Name OldLink1 As GetFullPic1  
    End If
    
    Me.UrlMapePD.Value = GetLink1
    Me.TxtUrlPic1.Value = GetLink1 & GetPic1
 

wiklendt

i recommend chocolate
Local time
Tomorrow, 06:30
Joined
Mar 10, 2008
Messages
1,746
Have you done debugging on the code: Which line returns the error?
 

guestbb

Registered User.
Local time
Today, 12:30
Joined
Jul 14, 2015
Messages
44
The line: Name OldLink1 As GetFullPic1
returns the error. I checked with ?OldLink1 and ?GetFullPic1. The links are correct but it doesnt want to rename. I think that Name function might not be able to rename folders. Maybe I am mistaken. Any ideas?
 

wiklendt

i recommend chocolate
Local time
Tomorrow, 06:30
Joined
Mar 10, 2008
Messages
1,746
Bit rusty on "Name" : what does MS Access Help tell you "Name" is used for?
 

wiklendt

i recommend chocolate
Local time
Tomorrow, 06:30
Joined
Mar 10, 2008
Messages
1,746
Also, if the user has changed txturlpic, then oldlink1 won't work anymore, I'd have thought.
 

guestbb

Registered User.
Local time
Today, 12:30
Joined
Jul 14, 2015
Messages
44
It doesnt actually say much to be honest. I googled how to rename folders and files. Found mostly how to rename files, but not folders as much (some said it worked for them) and Name was used for renaming files mostly. Is there any other way maybe to do this?
 

guestbb

Registered User.
Local time
Today, 12:30
Joined
Jul 14, 2015
Messages
44
Also, if the user has changed txturlpic, then oldlink1 won't work anymore, I'd have thought.

If the change txturlpic it is then for adding a new picture completly. I have another code that works with that.
 

wiklendt

i recommend chocolate
Local time
Tomorrow, 06:30
Joined
Mar 10, 2008
Messages
1,746
I can check some of my old code in about an hour. I think I've done something like this before.
 

wiklendt

i recommend chocolate
Local time
Tomorrow, 06:30
Joined
Mar 10, 2008
Messages
1,746
ok my project did something different involving deleting an image file and replacing it with a new one. never the less, i think we can sort this out.

i checked the microsoft help file for the Name statement and it appears that all the folders you need to use (new and old) need to already exist. What i understand, therefore that "Name" does, is it moves the file from an existing folder to another existing folder.

The Name statement renames a file and moves it to a different directory or folder, if necessary. Name can move a file across drives, but it can only rename an existing directory or folder when both newpathname and oldpathname are located on the same drive. Name cannot create a new file, directory, or folder.
do they exist, in your situation, or are you trying to create new folders? if not, you may need to look into "mkdir" and "rmdir" statements.

also, does the value of "TxtUrlPic1" include the file name and file extension?
 

guestbb

Registered User.
Local time
Today, 12:30
Joined
Jul 14, 2015
Messages
44
What I want is to rename folder and file that already exist. The txturlpic1 contains the filename and extension.
Example i have the old link X:\BASE DATAS\Yamaha\GTC 2.1 - John Mark\GTC 2.1 - John Mark.jpg
And if i changed some data in the textboxes it should be
X:\BASE DATAS\Yamaha\GTC 2.14 - John Mayer\GTC 2.14 - John Mayer.jpg
So it has to rename folders where the change was made and the files also
All of this data is in the code I wrote above, but the Name function doesnt seem to work for my situation
 

wiklendt

i recommend chocolate
Local time
Tomorrow, 06:30
Joined
Mar 10, 2008
Messages
1,746
What I want is to rename folder and file that already exist. The txturlpic1 contains the filename and extension.
Example i have the old link X:\BASE DATAS\Yamaha\GTC 2.1 - John Mark\GTC 2.1 - John Mark.jpg
And if i changed some data in the textboxes it should be
X:\BASE DATAS\Yamaha\GTC 2.14 - John Mayer\GTC 2.14 - John Mayer.jpg
So it has to rename folders where the change was made and the files also
All of this data is in the code I wrote above, but the Name function doesnt seem to work for my situation

So folder "X:\BASE DATAS\Yamaha\GTC 2.14 - John Mayer\" already exists before you make any changes?

Renaming a folder is not the same as having two pre-existing folders. I just want to be clear i understand your situation. "Name" requires that both the old and new folders already exist in the current folder structure, not just in code.
 

guestbb

Registered User.
Local time
Today, 12:30
Joined
Jul 14, 2015
Messages
44
No the new changed files and folder names dont exist. They are not created, I just renamed the string in the code with this and then I want to apply this to old folders and files to rename them not to create new folder. Just to rename old folders and files to the new names that were created with changes in my textboxes
 

wiklendt

i recommend chocolate
Local time
Tomorrow, 06:30
Joined
Mar 10, 2008
Messages
1,746
No the new changed files and folder names dont exist. They are not created, I just renamed the string in the code with this and then I want to apply this to old folders and files to rename them not to create new folder. Just to rename old folders and files to the new names that were created with changes in my textboxes

OK, so you first need to create the new directory. Use "MkDir" to first create the directory, then follow that up with your "Name" statement. I've not used "Name" before, so i'm not sure if deletes the old path and file, so if you need it removed you may also need "RmDir" (to delete old folders) and/or "Kill" (to delete old files).
 

wiklendt

i recommend chocolate
Local time
Tomorrow, 06:30
Joined
Mar 10, 2008
Messages
1,746
For what it's worth, i always have a 'friendly' text that is displayed for users, but i always name my associated file(s) by the primary key for that record - that way, if any data change, the underlying files are only associated with the primary key (that cannot change) and remain associated without any leg work from you, the coder. you can use your code to then call up that file if you ever need it - that is, the code doesn't need your files to be human-friendly.
 

wiklendt

i recommend chocolate
Local time
Tomorrow, 06:30
Joined
Mar 10, 2008
Messages
1,746
I've arrived at work now so I won't be able to look at this again until tonight. I have, hopefully steered you in the right direction.
 

Users who are viewing this thread

Top Bottom