Results 1 to 4 of 4
  1. #1
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    340

    Puzzle renaming network file



    Code:
     Name dn As Files(i)
    dn and Files(i) are correct. dn exists and files(i) is the corrected name in the same location. Both start with "\"
    I'm getting error "file not found". Is this because no drive letter is given?

    But also - when I cursor over the word "Name" is shows me the name of the Form. This isn't right , is it ?

  2. #2
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    340
    After some more testing it seems the problem isn't network addressing or the Name hover display. Its because the filename has no extension.
    Can this be converted to VBA ?
    Code:
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Try
                f.ShowDialog()
            Catch ex As Exception
            End Try
        End Sub
    
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            Dim Files As String() = IO.Directory.GetFiles(f.SelectedPath + "\", "*.*", IO.SearchOption.AllDirectories)
            Dim fil As String
            For Each fil In Files
                If System.IO.Path.GetExtension(fil) = "" Then
                    FileSystem.Rename(fil, fil & ".txt")
                End If
            Next
        End Sub
    Or, any other method to rename a file with no extension.

  3. #3
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,643
    But also - when I cursor over the word "Name" is shows me the name of the Form. This isn't right , is it ?
    No, It's not right but we dont know where your dn and Files(i) is coming from. They should be paths.

    Personally I like fso for copying, moving, renaming, etc., files and folders.

    Code:
    Public Sub fFileCopy(SourceF As String, DestinationF As String, Optional OvrWrite As Boolean = True)
    
    
        'Dim fso As New FileSystemObject                            'Early Bound- need refernce to MS Scripting runtime
        
        Dim fso As Object                                           'Late Bound
        Set fso = CreateObject("Scripting.FileSystemObject")
        
        fso.CopyFile SourceF, DestinationF, OvrWrite
        
        Set fso = Nothing
    
    
    End Sub
    
    
    Public Sub fFileMove(SourceF As String, DestinationF As String)
    
    
        'Dim fso As New FileSystemObject                            'Early Bound- need refernce to MS Scripting runtime
        
        Dim fso As Object                                           'Late Bound
        Set fso = CreateObject("Scripting.FileSystemObject")
    
    
        fso.MoveFile SourceF, DestinationF
    
        Set fso = Nothing
    
    End Sub
    Cant say that I understand your code but it looks like you're looking for files with no extension.

    fso also has a method to get the file extension

    Code:
    Function fGetExtension(sPath As String) As String
    
    
        'Dim fso As New FileSystemObject                            'Early Bound- need refernce to MS Scripting runtime
        
        Dim fso As Object                                           'Late Bound
        Set fso = CreateObject("Scripting.FileSystemObject")
        
        fGetExtension = fso.GetExtensionName(sPath)
    
        Set fso = Nothing
     
    End Function
    You can also use fso to recursively iterate through directories and subfolders to get all the files within. I don't have any sample code handy for that at the moment but there's plenty around.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  4. #4
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    340
    Hi Mole123, thanks for reply... dn and files(i) were paths + filenames. But there was no extension.
    The rename was to add the extension but I eventually gave up and did them all by hand!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Renaming Each File
    By DMT Dave in forum Access
    Replies: 41
    Last Post: 09-26-2019, 06:30 AM
  2. file on network wont open
    By sbrady19 in forum Access
    Replies: 10
    Last Post: 03-11-2015, 07:58 AM
  3. Replies: 8
    Last Post: 05-25-2014, 11:16 PM
  4. Renaming a file using VBA
    By bfaucher in forum Programming
    Replies: 1
    Last Post: 11-01-2011, 02:56 PM
  5. Replies: 0
    Last Post: 08-20-2008, 10:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums