Skip to main content

How to: Use filenames longer than 255 characters on Windows

The maximum number of symbols in a Windows pathname is 256, including file separators '/' or '\', but excluding the drive letter, and initial file separator (e.g. 'C:/'), and the string terminator ('\0'), cf. MSDN - Naming a File or Directory. In R, the limit is one symbol less, i.e. 255.


Here is an example of a very long pathname:

# Working directory:
pwd <- getwd()
## [1] "C:/Users/AromaUser/Project_2010/TCGA,GBM,analysis/redundancyTests/"

# Result directory:
path <- "cbsData/,pairs/GenomeWideSNP_6/"

# Filename
filename <- "TCGA-06-0208,01A,01D-0236-01,ratios,ref=TCGA-06-0208,10A,01D-0237-01,log2ratio,total,chr09,dbc39899be02529b41df0a9416537f0a.xdr"

# Complete pathname
pathname <- file.path(pwd, path, filename)

## [1] 267


This limitation typically reveals itself as "file" errors. One example is "In gzfile(file, "wb") : cannot open compressed file '<long pathname>', probable reason 'No such file or directory'. Another example is "Error in dirname(pathname) : file name conversion problem".


  1. Use a working directory that is higher up in the directory structure, e.g. instead of 'C:/way/too/long/path/' use 'C:/short/path/'.
  2. The [Windows/MS-DOS] console 'subst' utility makes a drive letter to any Windows directory, e.g. subst Y: 'C:/Documents and Settings/JohnDoe/Documents/My Research/Projects/aroma.affymetrix/ProjectA/'.
  3. The following R.utils solution maps the current working directory to 'Y:' (using the above internally) and updates the working directory to be 'Y:/':