Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I need to be able to count the number of characters in a full path to a file in windows. How I am currently accomplishing this task is as follows:

  1. Open a command prompt
  2. cd to the directory in question (for example c:\CruiseControl\ProjectArtifacts\ProjectName)
  3. type the following command dir /s /b > output.csv
  4. Open the resulting output.csv file in excel.
  5. use the =LEN() function in excel to count the number of characters per row as listed in the output.csv file.

Does anyone know of an explorer shell extension, or some 3rd party tool that could preform this function without me having to manipulate the output from dir in excel? Is there some easier way to go about doing this? The root of the issue I am having is the ~260 character file path limit in Windows. I am trying to analyze which paths are approx ~260 characters so I can shorten them to avoid getting this error.

share|improve this question

3 Answers 3

up vote 1 down vote accepted

This kind of thing is very easy to do with Hamilton C shell. If this a one-time thing, you'll be happy with the free version. Here's an example generating the fullpaths of several files in the c:\Windows directory, then computing the string lengths. Full disclosure: I'm the author.

128 C% cd
c:\Windows
129 C% ls mi*
Microsoft.NET      Minidump           mib.bin
130 C% foreach i ( mi* )
131 C? @ f = fullpath ( i )
132 C? echo $i $f $strlen(f)
133 C? end
mib.bin c:\Windows\mib.bin 18
Microsoft.NET c:\Windows\Microsoft.NET 24
Minidump c:\Windows\Minidump 19
134 C%
share|improve this answer
    
Nicole - Very impressive btw! This is exactly what I needed. I will add a reminder to my calendar to buy a full copy when my next check arrives. –  Richie086 Nov 12 '12 at 23:25
    
FYI I went ahead and purchased the Hamilton C Shell. I will be sure to let people know about this great product! –  Richie086 Nov 12 '12 at 23:34
    
Nicole - how would I recurse into sub directories and also list the total path length of files in each directory? Your example works well for listing the number of characters in the directories, but not the files in each directory. –  Richie086 Nov 12 '12 at 23:52
    
As discussed offline, one very easy way to treewalk an entire directory is with the ... wildcard, e.g., foreach i (...\*) echo $i; end. The ... construct means "0 or more directory levels, whatever it takes to make the rest of the pattern match." –  Nicole Hamilton Nov 13 '12 at 1:56

This is not an answer to your question, but it addresses your problem.  Type

dir /s /b | findstr -r ...............................................................................................................................................................................................................................................................

In my illustration above, I have typed 255 periods; this will do the dir /s /b, which you already know, and show only the lines (file pathnames) that are at least 255 characters long.  Adjust the number of periods to your liking.  Naturally, you can redirect the output of the above to a file for printing or other analysis.

share|improve this answer

Maybe these simple batch files will come in handy.

1) Counting the number of characters in the current directory:

@echo off
echo %cd%>"%TMP%\Temp.txt"
for %%l in ("%TMP%\Temp.txt") do set /a len=%%~zl
del "%TMP%\Temp.txt"
set /a len-=2
echo Path length = %len% chars.

cd to the dir. and just call the batch file.

2) Counting the number of characters in the specified directory:

@echo off
echo %1>"%TMP%\Temp.txt"
for %%l in ("%TMP%\Temp.txt") do set /a len=%%~zl
del "%TMP%\Temp.txt"
set /a len-=4
echo Path length = %len% chars.

Call the batch file and pass the full path as an argument to it (be sure to use quotes if the path contains spaces). Note that no error checking is done, so leaving out quotes when the path contains spaces will give an incorrect (low) count, and adding extra backslashes at the end will increase the count.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.