Move File: The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters

Exception:

Move File or Copy File:

The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.

Solution Tried:

Directory.GetFiles(“yourdirpath”).[Select](Function(f) New FileInfo(f)).Where(Function(f) f.CreationTime = DateTime.Now AndAlso f.Extension.Equals(“.pdf”) ).ToList()

(Same issues)

Tried Macro

Working fine

Sub FSOMoveAllFiles ()
Dim FSO As New FileSystemObject
Dim FromPath As String
Dim ToPath As String
Dim FileInFromFolder As Object
FromPath = “A1”
ToPath = “A2”
Set FSO = CreateObject(“Scripting.FileSystemObject”)
For Each FileInFromFolder In FSO.GetFolder(FromPath).Files FileInFromFolder.Move ToPath Next FileInFromFolder
End Sub

@mukeshkala @Vibhor.Shrivastava @Vrinda_Jain @nisargkadam23 @Lahiru.Fernando @seanrockvz13 @StefanSchnell

2 Likes

@Manikandan_Ckj

As the error states It’s the issue with the FileName / the Path or the both are very long which is not in the permitted

As this exception is from Windows, So try to reduce your path or FileName will solve your issue

Hope this may help you

Thanks

1 Like

@Manikandan_Ckj

There is also a way for you to edit windows registry settings to allow file paths that go beyond 256 characters. I remember we ran into this issue in one of the projects, and we changed this setting to fix it.

2 Likes

Hi @Manikandan_Ckj,

As @Lahiru.Fernando suggested, if all approaches fail then the last option will be to fix this by editing registry setting.

There is another option as well. Refer the solution from @otico in this thread (Option 2).

1 Like