How to delete a file with 0 bytes, but read "þa" from it in a c program
This question is not the same as How to delete an invincible 0 byte file? since none of the answers have worked and my impossible to delete file I "feeeel" is different.
I was following this website to delete a folder with a node_modules folder. These take forever to delete using the File Explorer, and I can never remember the exact command to run every time. So I looked it up.
https://www.ghacks.net/2017/07/18/how-to-delete-large-folders-in-windows-super-fast/#:~:text=Tap%20on%20the%20Windows%2Dkey,F%2FQ%2FS%20*.
I use the following command or my fudgy fingers and terrible eyes processed what I thought was: DEL /F/Q/S *.* > NUL
This deleted all of the files in the folder, but created this NUL file with 0 bytes. This tells me I messed up the command and something was piped to NUL when the link says > NUL
is suppose to disable console output.
I've tried File Commander, del *.
, del *.*
, dir /x
doesn't show anything different from dir
, the delete button in the file explorer, specifying all permissions on the file and trying everything again. Doesn't work.
I tried piping text into it hoping life could get easier if it had something in it. This didn't pipe any text into the file: echo "Hello world" > NUL
Being a programmer, I thought I could go deeper and write a c program to delete it. Nope. Didn't work.
if(remove("C:/../../NUL") == 0)
printf("Deleted successfully");
else
printf("Unable to delete the file");
I tried writing text to the file in C and that also failed. Then I tried reading from it and writing the buffer stream to a new file.
FILE *fp;
FILE *fp2;
char buff[255];
fp = fopen("C:/../../NUL", "r");
fp2 = fopen("C:/../../cmd.txt", "w");
fgets(buff, 255, (FILE*)fp);
fputs(buff, fp2);
fclose(fp);
fclose(fp2);
I found two characters are in it. þa. No idea what "þa" represents. When I print the characters out to the console in Eclipse there's three of them and they are " aw". The first character is a blocked question mark. It's a little different looking from the Unicode replacement character. So now I'm here and left will a Scooby Doo mystery of these mysterious characters, a fudged command that created these characters, and a file that's unable to be deleted.
For some reason the first character in the string isn't saving so I grabbed some snippets from the Eclipse console output and for some reason Chrome also rendered it differently so I snagged a picture from there too. https://ibb.co/yQSfD8b
--UPDATE-- I ran the command DEL /f/q/s . > NULL. Running the flags with lowercase values are what messed me up.
This question has already been answered on stackoverflow here.
A shameless copy/paste in case that link should ever die:
Open a command prompt and use these commands to first rename and then delete the NUL file:
C:\> rename \\.\C:\..\NUL. deletefile.txt
C:\> del deletefile.txt
Using the \\.\
prefix tells the high-level file I/O functions to pass the filename unparsed to the device driver - this way you can access otherwise invalid names.
Read this article about valid file / path names in Windows and the various reserved names.