0

I am a newbie Python beginner. Need help with a code to output all folders in my D drive of my Windows 10 machine which have files (sub-folders -> subfolders etc) which has length more than 250 characters.

I have subscribed for cloud backup of a very popular cloud backup provider which has 250 characters file path length limit. So, it automatically excludes all files which have length more than 250 chars. So, it would be very helpful if I get a few lines of code which outputs the below:

Output -> All the root folders in D drive which have files which have more than 250 char length so that I can shorten the length of those folders specifically. I have 5 TB data so it's obvious that it's not a manual task.

Thanks for understanding.

  • Do you mean the 250 filename limit? Do you actually have files with names greater than 250 characters? I think the limit applies only to the single filename, not it's full path – Maxxik CZ Dec 13 '19 at 13:00
  • @MaxxikCZ I wish it was the case, Max. It actually applies to the full path length :( – Abhishek SIngh Dec 13 '19 at 13:04

1 Answers1

0

Since you are already on windows here's a small script I could come up with:

Create a batch file and put below code into it (script.bat):

@echo off
setlocal EnableExtensions DisableDelayedExpansion
SET /P var=Enter max char:
(for /r %%I in (*) do (
  set "fn=%%~nI"
  if not defined fn set "fn=%%~xI"
  setlocal EnableDelayedExpansion
  if not "!fn:~%var%!" == "" echo %%~fnxI
endlocal
))>output.txt
endlocal

Steps:

1) Run this batch file. 2) it will ask for maximum chars allowed, insert 256 in your case.

Result: output.txt will be generated in your working directory which contains list of file names which are greater than provided input charater.

You can modify your scripts further as per requirements. You can refer to: https://ss64.com/nt/for_d.html