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


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.

Hello @emily

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


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)


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?


@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?


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:

For Each

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


  • For Each

Both doesn’t’ seems to work

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

Try to use LongPathTool. Working 100%. :slight_smile:

I’ve had the same problems in the past. I just use . It works wonders.

You should try LongPathTool. It’s the best software

Try LongPathTool for this problem

Try to use Long Path Tool, it really can help you with that.
It will really help you to solve your problem.