How to Solve Error Msg: The specified path, file name, or both are too long

Hi,

I faced this error message:
“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.”

I am using the following code to get the array list of file names
Directory.GetFiles(“directory path”,“*”,searchOption.AllDirectories)

There are manly levels for the folder structure thus the path is long. Is there any way to increase the character limits or ways for me to get the path? Thanks.

1 Like

Hello @emily

Hope you are doing well,you are almost there you can do this

Directory.GetFiles(“FolderPath”)

if you want file names form the folder you can do this

  • Use For Each and pass this as input Directory.GetFiles(“FolderPath”) and make argument type as String

  • Now inside for each loop you can use message box like this Path.GetFileNameWithoutExtension(item)

Cheers
@emily

1 Like

Hi @Pradeep_Shiv, thanks for the reply. I managed to get the file and folder names but as there are many level of subfolders, the path become really long so I’m face with the error msg. Is there any way I can increase the characters limit?

I need to store the full path so wondering if there are any ways so I can store the path?

Thanks.

@emily - can you share a 2 sample filepaths? (with out exception & with exception)

Hi @GBK,

I have the error msg when it is running the for each where my input: Directory.GetFiles(“directory path”,“*”,searchOption.AllDirectories)

I guess some of the file path is too long: I can’t put the full path here but it exceed 260 characters. I have also tried to map the path as a network drive to shorten the path but it doesn’t work as well.

I couldnt see which path the bot stuck at that shows the error msg, is there any way I can see it?

Thanks.

Hi @emily - you can add the logic between try/catch and log the file path along with exception details exception section. so that it will be easy for us to track the issue.

Hi @GBK, could you advice how to log the file path? I tried to following:

#1
For Each

  • Try (Sequence)
  • Catch (write line (item))

#2
Try

  • For Each
    Catch

Both doesn’t’ seems to work

@emily - option#1 is better to find the exception item . pls add - item and exception message…

I am also facing this error can anyone help me how to resolve

Hi there,

What package can i download that will allow me to see the longPathTool

Hii,

Is There any Solution For this Problem

Did you get any solution to this Exception?
Now i also facing same issue
@emily

Someone find anything for this situation?

The proper solution is to set your system to allow long paths, or fix your paths so they don’t violate the Windows path length limit.

Also, please stop digging up old posts to spam your tool.