Giter Site home page Giter Site logo

superdelete's Introduction

SuperDelete

Deletes a file with a REALLY long file name.

Why Use This?

A while ago, I made a program with a bug in it. Altough it was only a trivial bug, the results from its execution proved to be quite messy. My program, written in Java, had created a file with an exceptionally long file name. This file name was so long that Windows was not able to move, rename, or delete it. The command prompt proved to be equally useless.

Actually, I initially had 3 files that were too long to delete. Using the command:

dir /x

I was able to find the "short name" of each of those files. By referring to these short names, I was able to delete one of them using:

erase SHORTFILENAME

However, this failed to work for the other two. No other method yielded frutiful results until I found this page. Bascially, the part of the article that helps us is that we are able to bypass the 256 character limit through the use of the Windows API. By prepending \?\ to an absolute path, we can extend the max to over 32,000 characters!

So I put together a little program I call Super Delete. Pass in the absolute path of a file you need to delete and it'll do it, even if the file name is extremely long.

#include <Windows.h>
#include <string>

using namespace std;

int main(){
  // Absolute path to file, with \\?\ prepended
  string path = "\\\\?\\C:\\Users\\Path\\To\\Long\\FILENAME.txt";
  const char * arr = path.c_str();
  
  // Call DeleteFile from the Windows API
  DeleteFile(arr);

  // And That's it!
  return 0;
}

superdelete's People

Contributors

yuhao93 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.