Sunday, September 24, 2023

Find files with path lengths exceeding CD/DVD restrictions using Windows PowerShell

If you have been burning CDs or DVDs for your personal archives or any other purposes, you already know it allows file paths only up to 255 characters. If you are burning files in bulk it an often difficult to ensure that your file path lengths confirm to the prescribed limits. Or if you are like me, then you probably want to limit the path length to 100-150 characters for manageability and protection against burn failures.

For this example, we consider a bunch of subfolders and files in a local drive path named "D:\MUSIC-Full-Backup\BACKUP0933\ARCHIVE05". We intend to burn the content inside this folder on the root of a DVD disc. For this purpose, we want to know which files here breach the 100-character limit of path length so we can take appropriate action to correct this.

Open the Windows PowerShell and change directory to "D:\MUSIC-Full-Backup\BACKUP0933\ARCHIVE05". Next run the following command at the prompt:

cmd /c dir /s /b *.* |?$curPath="D:\MUSIC-Full-Backup\BACKUP0933\ARCHIVE05"; $_.length-$curPath.length -gt 100 }

Here we are deducting the length of the current path from the full path of each file as it will not be part of the patch when it is burned the DVD. This should list all files in the folder which exceeds the length of 100 characters. An example output is below.

D:\MUSIC-Full-Backup\BACKUP0933\ARCHIVE05\Greatest Collection of the Century\JD YNK ULEATOBS NKY ULEATOBS\ARH OKIKIS VS LSNEIA LYTFTUREB JD KYN MAHUSP IXM.mp3
D:\MUSIC-Full-Backup\BACKUP0933\ARCHIVE05\Greatest Collection of the Century\JD YNK ULEATOBS NKY ULEATOBS\REMAD NO VS UHJT EINM ARB ILIONV TEEHM IMX FT SPEENAD.mp3
D:\MUSIC-Full-Backup\BACKUP0933\ARCHIVE05\Greatest Collection of the Century\JD YNK ULEATOBS NKY ULEATOBS\UHTJE HULBA IADY RESROPIVSEG NRETAC IMX.mp3

Now you can go to the individual folder and plan your strategy for shortening the path lengths.

No comments:

Post a Comment