Find file paths longer than 260 characters
Moderator: DosItHelp
Find file paths longer than 260 characters
I used: dir /s /b | sort /r /+261 /o out.txt
I expected to see the longest path on top.
However, I get about 830 lines with path longer than 260 and then there are more (longer than 260) listed starting on line 258214!
Why is that?
Also, Upon the file creation, I get about 50 warnings that "The directory name ... is too long"
Is my output a complete list?
Thanks
win xp sp2
edit: Can a directory or list of directories including their subdirectories be excluded from dir *.txt /s /on /b ?
I expected to see the longest path on top.
However, I get about 830 lines with path longer than 260 and then there are more (longer than 260) listed starting on line 258214!
Why is that?
Also, Upon the file creation, I get about 50 warnings that "The directory name ... is too long"
Is my output a complete list?
Thanks
win xp sp2
edit: Can a directory or list of directories including their subdirectories be excluded from dir *.txt /s /on /b ?
Re: Find file paths longer than 260 characters
The List is sorted in reversed sort order for names longer than or equal to 261 characters. ('z' to 'a' instead of 'a' to 'z' for example).drgt wrote:I used: dir /s /b | sort /r /+261 /o out.txt
I expected to see the longest path on top.
However, I get about 830 lines with path longer than 260 and then there are more (longer than 260) listed starting on line 258214!
Why is that?
In common this has nothing to do with the length of the filename String:
aaa
b
ccc
No, the directories which are too long are not listed.drgt wrote:Also, Upon the file creation, I get about 50 warnings that "The directory name ... is too long"
Is my output a complete list?
In addition hidden files/directories are not listed, too.
No, you have to use another command/batch (for example the 'for'-command).drgt wrote:Can a directory or list of directories including their subdirectories be excluded from dir *.txt /s /on /b ?
penpen
Re: Find file paths longer than 260 characters
Let me make it a bit clearer
In the out file, the first 7 lines are 265 characters long.
Lines 8-16 are 273 characters long.
Lines 17-24 --> 266
...
832-907 --> 74
...
258214 --> 261
...
I did not understand what you mean by
aaa
b
ccc
"for example the 'for'-command"
Could you please show?
Thanks
In the out file, the first 7 lines are 265 characters long.
Lines 8-16 are 273 characters long.
Lines 17-24 --> 266
...
832-907 --> 74
...
258214 --> 261
...
I did not understand what you mean by
aaa
b
ccc
"for example the 'for'-command"
Could you please show?
Thanks
Re: Find file paths longer than 260 characters
This is a proof, that the content of a string is not bound to its length.drgt wrote:I did not understand what you mean by
aaa
b
ccc
If you sort the above strings using "sort" or "sort /r", the result always is that "b" is sorted between "aaa" and "ccc".
The reason is the (natural) character order of the first character in each string:
'a' < 'b' < 'c'.
Example for listing all files "C:\Users\" and all its subdirectories, except all files/(sub)directories in "C:\Users\penpen" (untested - actually i'm posting from mobile phone):drgt wrote:Could you please show?
Code: Select all
@echo off
for /r "C:\Users\" %%a in (.) do (
echo %%a | >nul findstr "^C:\Users\penpen" || (
pushd "%%~a"
2>nul dir /A:-h-d /b
2>nul dir /A:h-d /b
popd
)
)
goto :eof
penpen
Re: Find file paths longer than 260 characters
Penpen,
I think they are not understanding your example because they are sorting on position 260.
So using your example:
But I think they think the longest will always sort to the top but that is not the case if the position you are sorting on has a blank.
I think they are not understanding your example because they are sorting on position 260.
So using your example:
Code: Select all
H:\sort>dir /b |sort /R /+3
ccc
aaa
b
But I think they think the longest will always sort to the top but that is not the case if the position you are sorting on has a blank.
Code: Select all
H:\sort>dir /b |sort /R /+3
ccc
aaa
aa b
b
-
- Posts: 240
- Joined: 04 Mar 2014 11:14
- Location: germany
Re: Find file paths longer than 260 characters
Can you give the result of this codeline, please?
Phil
Code: Select all
dir /s /b 1>nul 2>lt &&<lt set /p "X="&del lt &cmd /v/s/c"cls&echo(!X!:"
Phil
Re: Find file paths longer than 260 characters
@penpen
Respectfully, please explain the code you wrote above.
@Squashman
Paths do not have blank spaces.
So how we get the longest to be listed first?
@pieh-ejdsch
Hey Phil, would you please explain the code.
(You guys are so advanced you could have me try del *.* and answer yes too!) xaxaxaxaxa
Respectfully, please explain the code you wrote above.
@Squashman
Paths do not have blank spaces.
So how we get the longest to be listed first?
@pieh-ejdsch
Hey Phil, would you please explain the code.
(You guys are so advanced you could have me try del *.* and answer yes too!) xaxaxaxaxa
-
- Posts: 240
- Joined: 04 Mar 2014 11:14
- Location: germany
Re: Find file paths longer than 260 characters
this codeline will Output the first errormessage of Dir.
I want use this to find Paths longer than X and will become Driveletters Auto.
For german Output i use a Script.
also you can find Long pathes with Robocopy.
Phil
I want use this to find Paths longer than X and will become Driveletters Auto.
For german Output i use a Script.
also you can find Long pathes with Robocopy.
Phil
Re: Find file paths longer than 260 characters
Aha! Ok, it didn't cross my mind to use an example with offset, or to explain why the offset is irrelevant.Squashman wrote:Penpen,
I think they are not understanding your example because they are sorting on position 260.
It's all the same to me (but that may not apply to others):
If there is an offset, then the lines are compaired as if they have that offset less characters at the beginning.
So i think i should extend my example up to an offset of n (the '?' char is placeholder for any single character):
Code: Select all
:: example strings to be sorted using an offset of 1 (== no offset)
aaa
b
ccc
:: example strings to be sorted using an offset 2
?aaa
?b
?ccc
:: example strings to be sorted using an offset 3
??aaa
??b
??ccc
:: example strings to be sorted using an offset n
??????????.... n-1 times.....????????????aaa
??????????.... n-1 times.....????????????b
??????????.... n-1 times.....????????????ccc
The order of the first characters compared to each other is 'a' < 'b' < 'c'.
Ok.drgt wrote:please explain the code you wrote above.
The "for /R" loops on the the path specified, and all its directories (in this case "C:\Users\" and all subdirs).
It also filters these directories by the set specified (in this case the '.', which simply means any).
Within each directorie i check if that path should be ignored (i selected the path "C:\Users\penpen" and all its subdirs to be ignored; the '^' character is a regular expression which means "line start"):
I perform the check by echoing the actual pathname via a pipe to findstr which checks, if the pathname starts with the path to be ignored;
if findstr finds the string specified, then it returns 0 else 1;
The "||" is a conditional execution statement, which only executes if the leading statement exited with != 0.
So within the inner compbound statement (or block), i change to the actual looped directory (using pushd),
list all non directories (== files) that are not hidden, after that all files that are hidden, and then
i return to the directory before changing to the actual one.
The loop should result in a complete list of files of "C:\Users\" and all its subdirectories without all files within "C:\Users\penpen" (still untested for the same rason).
(You probably have to change these parameters to match your requirements.)
Sidenote:
This only is an example implementation to demonstrate how to exclude subdirectories.
It does not solve the issue "The directory name ... is too long".
Depending on your directory structure it may be sufficient to use subst; extending my above example (assumed Z: is an unused volume on your system):
Code: Select all
@echo off
subst "Z:" "C:\Users"
for /r "Z:\" %%a in (.) do (
echo %%a | >nul findstr "^Z:\penpen" || (
pushd "%%~a"
2>nul dir /A:-h-d /b
2>nul dir /A:h-d /b
popd
)
)
subst /d "Z:"
goto :eof
penpen
Re: Find file paths longer than 260 characters
Ok. Thank you all for your input.
To sum it up
using
dir /a-d /on /s /b >c:\out.txt on the root of the drive
will make a file in which all files of the drive including hidden and system will be listed
AND
if at the command prompt window I get 50 "This directory ..... is too long", that means that I have ONLY THESE 50 directories whose length is longer than 260 characters.
CORRECT?
To sum it up
using
dir /a-d /on /s /b >c:\out.txt on the root of the drive
will make a file in which all files of the drive including hidden and system will be listed
AND
if at the command prompt window I get 50 "This directory ..... is too long", that means that I have ONLY THESE 50 directories whose length is longer than 260 characters.
CORRECT?
Re: Find file paths longer than 260 characters
Yes, both is correct, but depending on your system creating a file on your root of drive may be prohibited.
I'm unsure about the following things (i never tested it):
- It might be that the error message "The directory name ... is too long" is produced multiple times (for every file in a directory with >260 charcters in it).
- Also it might be that the directory listing in a directory with a too long subdir, the listing is aborted, so there might be more pathes than these 50 directories with too long path names in your case.
- Another thing might be, that this directory name too long message only contains a fixed size prefix of the complete pathname of that directory.
You have to check these things out.
You should notice that i seem to have overcomplicated things... with the for loop, as you could also exclude pathes by using findstr directly with the dir output:
But i fear you have to use some kind of a for loop to collect those overlong pathnames.
Maybe you could filter the "overlong candidates" using something like this (and use a for /F loop on the resulting text file to get the path names; untested):
penpen
I'm unsure about the following things (i never tested it):
- It might be that the error message "The directory name ... is too long" is produced multiple times (for every file in a directory with >260 charcters in it).
- Also it might be that the directory listing in a directory with a too long subdir, the listing is aborted, so there might be more pathes than these 50 directories with too long path names in your case.
- Another thing might be, that this directory name too long message only contains a fixed size prefix of the complete pathname of that directory.
You have to check these things out.
You should notice that i seem to have overcomplicated things... with the for loop, as you could also exclude pathes by using findstr directly with the dir output:
Code: Select all
dir /a:-d /on /s /b | findstr /v "^C:\path\to\exclude" >"c:\some path\out.txt"
But i fear you have to use some kind of a for loop to collect those overlong pathnames.
Maybe you could filter the "overlong candidates" using something like this (and use a for /F loop on the resulting text file to get the path names; untested):
Code: Select all
2>&1 (>nul dir /a:-d /on /s /b) | findstr /v "^C:\path\to\exclude" >"c:\some path\out.txt"
penpen