Skip to content

How to Delete a PDF File with Long Name via PowerShell

Have you ever found yourself struggling to delete a PDF file because its name exceeds the limitations? We’ve all been there! Whether it’s due to a pesky character limit or an overly long and convoluted file name, trying to get rid of that unwanted PDF can be frustrating. If a file name is too long, you may not be able to copy, move, rename, or delete it. In this tutorial, we’ll check out quick and easy ways to delete a file with a long name from the desktop on Windows 10 and 11.

Why Can’t You Delete a PDF from Your Desktop

The reason why you can’t delete a text or PDF file from your desktop may be because its name is too long. The root cause of this irritating problem lies in LFN. Windows uses a naming convention called LFN (long filename). The LFN system allows the operating system to recognize only those files and directories which use up to 255 characters in their names. You might get an error while copying, moving, renaming, or deleting a file with a very long file name if the location where you want to move the file has a longer path than the file’s original location. The location may be a folder or the Recycle Bin where the file goes when you delete it.

Recently, I have been through a frustrating moment when I had to struggle with a pesky restriction that prevented me from renaming and deleting a PDF file from my desktop. I was fined for unauthorized car parking. After paying the fine amount online, I downloaded the PDF receipt to the desktop. It opened normally in Google Chrome but later, I noticed that the name of the PDF file was too long.pdf file on windows desktop with very long name

echallan.parivahan.gov.in_report_print-challan-receipt_data=tM3pJ01qgJECukxDSxFLFedcTWVTluS958p4lTVFZH7TNy8Uwc6a69YC9T5X0CH%2FWMwoVYuW32l3Cy7eGNgJwgB0YKLD6ycbHzDkh3yJ8asmOcroqXEb1vZQOEBY1Ajp6q2UPIRvX1pXOo1jVWAwSBM0567J7roSFhtE6MZFOnNFLUfmdjVJ1X9vI25VK.pdf

When I tried to rename the PDF file so that I can assign it a short name, I couldn’t do that. Suspecting that it might be malware, I tried to delete it instantly but it was futile. Then I tried to move the PDF file to a folder so that I can delete it along with the folder but I was unable to do that too.delete pdf from desktop windows 11

Having done some research online, and trying different methods, I was finally successful in deleting the PDF file with a long name from my desktop using a Windows PowerShell command.

Steps to Delete a File with a Long Name Using PowerShell

Whether it’s due to a pesky character limit or an overly long and convoluted file name, trying to get rid of that unwanted PDF can be frustrating. Below, I’ll walk you through a quick and effective solution to delete a stubborn PDF file with an excessively long file name.

Just like LFN (long filename), Windows also supports the SFN (short filename) convention used by DOS and older versions of the OS. It works like an alternative filename system in Windows 10 and 11. SFN (aka 8.3 filename) is limited to 8 characters followed by a file extension. Thanks to the backward compatibility of Windows that assigns an 8-character short filename to the file whose filename exceeds 255 characters.

For instance, the PDF file name I mentioned above also had a short filename which consisted of only 8 characters. Once you have that SFN or 8.3 filename, you can easily delete any file with a long name using the DEL command in the PowerShell or the Windows Command Prompt.

Let’s see how to do it.

  1. Right-click on the file whose name is too long and you are not able to delete and choose the Copy as path option to copy the file path.copy as path option in windows 11
  2. Now, paste the copied file path into a text file. The path will contain the 8-character short filename of the file you can’t delete. In my case, the short filename of the PDF file I mention above was ‘ECHALL~1.PDF‘ as in “C:\Users\droid\Desktop\ECHALL~1.PDF”
  3. Copy the short filename to the clipboard.
  4. Now, navigate to the directory or desktop where that stubborn file is located.
  5. Hold the Shift key and right-click on an empty area and select the Open in Terminal or Open PowerShell window here option from the Windows context menu.open powershell window here windows 11
  6. Execute the DEL command followed by the filename (with extension) of the file you want to delete.
    DEL Filename.PDF

    delete file with long name using windows powershell

  7. As soon as you hit the Enter key, the file you couldn’t delete earlier will be deleted.

The deleted file will disappear from your computer completely. It won’t be even sent to the Recycle Bin. Using this method, you can delete any file with a long name. It doesn’t matter whether it is a PDF or text file or has any other extension.

We hope that this step-by-step guide has helped you figure out how to delete a PDF when the file name exceeds limitations. This process can be tricky, but with our tips, you’ll be able to make sure your files are correctly named and organized so that they don’t cause any further issues in the future. If you find yourself needing additional assistance with managing your PDFs or other documents, feel free to reach out for help from one of our experts.

Read Next: 250+ Windows 10/11 Keyboard Shortcuts

2 thoughts on “How to Delete a PDF File with Long Name via PowerShell”

  1. Unfortunately, this didn’t work for me in Windows 11. I receive an error saying I don’t have sufficient access rights to perform the operation, even when the PowerShell is run as an admin. And it says it can’t find the specified file when I tried via dos prompt even though it lists the full file name prior to the error message.

  2. Hello, I did exactly as you said and this is the result:
    PS C:\Users\Admin\Desktop> DEL stahls.com_stahls_content_printPreview.html_f=Varsity&u=https___dyn.stahls.com_nn_api_namenumber_render.ashx_Names=1 2 3 4 5;6 7 8 9 0&TextStyle=(Brush_Color_000000,Font_(Size_32,Path__namenumber_stahlsid_Stahls%27_Varsity+))&Pack=(Type_BestFitPreview.pdf

    Then I used CMD.exe and this is the result:

    C:\Users\Admin\Desktop> DEL stahls.com_stahls_content_printPreview.html_f=Varsity&u=https___dyn.stahls.com_nn_api_namenumber_render.ashx_Names=1 2 3 4 5;6 7 8 9 0&TextStyle=(Brush_Color_000000,Font_(Size_32,Path__namenumber_stahlsid_Stahls%27_Varsity+))&Pack=(Type_BestFitPreview.pdf
    Could Not Find C:\Users\Admin\Desktop\stahls.com_stahls_content_printPreview.html_f
    ‘u’ is not recognized as an internal or external command,
    operable program or batch file.
    ‘TextStyle’ is not recognized as an internal or external command,
    operable program or batch file.
    ‘Pack’ is not recognized as an internal or external command,
    operable program or batch file.
    C:\Users\Admin\Desktop>

    I hit ENTER and I get :
    >>

    I hit ENTER aging and I get:
    At line:1 char:58
    + DEL Stahls.com_stahls_content_printPreview.html_f=Varsity&u=https___d …
    + ~
    The ampersand (&) character is not allowed. The & operator is reserved for future use; wrap an ampersand in double
    quotation marks (“&”) to pass it as part of a string.
    At line:1 char:132
    + … .stahls.com_nn_api_namenumber_render.ashx_Names=1 2 3 4 5;6 7 8 9 0&T …
    + ~
    Unexpected token ‘7’ in expression or statement.
    At line:1 char:134
    + … tahls.com_nn_api_namenumber_render.ashx_Names=1 2 3 4 5;6 7 8 9 0&Tex …
    + ~
    Unexpected token ‘8’ in expression or statement.
    At line:1 char:136
    + … hls.com_nn_api_namenumber_render.ashx_Names=1 2 3 4 5;6 7 8 9 0&TextS …
    + ~
    Unexpected token ‘9’ in expression or statement.
    At line:1 char:138
    + … s.com_nn_api_namenumber_render.ashx_Names=1 2 3 4 5;6 7 8 9 0&TextSty …
    + ~
    Unexpected token ‘0’ in expression or statement.
    At line:1 char:139
    + … .com_nn_api_namenumber_render.ashx_Names=1 2 3 4 5;6 7 8 9 0&TextStyl …
    + ~
    Unexpected token ‘&’ in expression or statement.
    At line:1 char:169
    + … ashx_Names=1 2 3 4 5;6 7 8 9 0&TextStyle=(Brush_Color_000000,Font_(Si …
    + ~
    Missing argument in parameter list.
    At line:1 char:183
    + … 3 4 5;6 7 8 9 0&TextStyle=(Brush_Color_000000,Font_(Size_32,Path__na …
    + ~
    Missing argument in parameter list.
    At line:1 char:230
    + … Font_(Size_32,Path__namenumber_stahlsid_Stahls%27_Varsity+))&Pack=(Ty …
    + ~
    The ampersand (&) character is not allowed. The & operator is reserved for future use; wrap an ampersand in double
    quotation marks (“&”) to pass it as part of a string.
    At line:1 char:260
    + … amenumber_stahlsid_Stahls%27_Varsity+))&Pack=(Type_BestFitPreview.pdf
    + ~
    Missing closing ‘)’ in expression.
    + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : AmpersandNotAllowed
    PS C:\Users\Admin\Desktop>

    I should mention that when I do a “C:\Users\Admin\Desktop>dir” I get the file in the list of files on the desk top.

    Thank you

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.