Friday, 2 August 2019

windows - The Directory name is too long in batch

I already asked the question in stack overflow, but did not get any answer from anyone. So i am asking the same question here also.


I am trying make a program which will calculate size of all folder present in the specified location or the current location using a batch script and i am writing it into a .csv file


I followed this question in stackoverflow


https://stackoverflow.com/questions/21711180/how-to-list-all-folder-with-size-via-batch-file


and my code is


`@echo off
setlocal disabledelayedexpansion
set "folder=%~1"
Set "Value=0"
if not defined folder set "folder=%cd%"
(for /d %%a in ("%folder%\*") do (
set "size=0"
for /f "tokens=3,5" %%b in ('dir /-c /a /w /s /x "%%~fa\*" ^| findstr /b /c:" "')do if "%%~c"=="" set "size=%%~b"
setlocal enabledelayedexpansion
echo(%%~nxa , !size!
endlocal
))>>foldersize.csv
endlocal
exit /b`

When i run the code, i am getting an error



The directory name "dir_name" is too long



I already knew that the maximum length for a windows path name is 260 character and that might be the reason for this error.


Is there any way I can solve this problem ??


Thanks in advance for every response.

No comments:

Post a Comment

How can I VLOOKUP in multiple Excel documents?

I am trying to VLOOKUP reference data with around 400 seperate Excel files. Is it possible to do this in a quick way rather than doing it m...