1

enter image description here

There is 2 loader.bin. But one of them has carrage return at the end of the file name. Because of this, I can't delete the file, and directory containing the file. Even with command prompt, I can't delete it. I tried:

del *
del loader.*

above says name or label is wrong. So I

cd ..
dir /x

to check DOS path name of the directory And delete with DOS path del TEXT_L~1 and again, above says name or label is wrong.

I also tried to delete the directory with "\?\" prefix. something like:

del "\\?\D:\directory\blahblah\directory"

and again, name error occurs.

How can I delete this file? Can I have some hint?

I guess that there is carriage return at the end of name because auto complete in git bash complete the name as "loader.bin^M"

I think the file came from wrong command from batch file like:

fasm file.asm loader.bin(here's carriage return)

(fasm is assembler program) Batch file's end of line may have been changed while I changed platform from linux to windows.

EDIT: The file refused to get deleted with following method too.

  1. delete with /P option

    del /P directoryName
    
  2. with DeleteFileW windows API

    #include <windows.h>
    int main()
    {
        DeleteFileW(L"E:\\directory\\blahblah\\directory");
    }
    
Taeyun
  • 211
  • 2
  • 16
  • The ``\\?\`` prefix can only bypass limits imposed by DOS compatibility. In this case, the issue is instead that NT filesystems disallow control characters (ordinals 1-31) in filenames, so there's no way to open a handle to the file to rename or delete it. Maybe there's a low-level approach using a filesystem IOCTL. – Eryk Sun Aug 05 '17 at 05:11
  • In Windows 10 I can create and delete a file with the name `"loader.bin\r"` in a Virtualbox shared folder that's hosted in Linux. It doesn't even require the ``\\?\`` prefix. This shows that success here depends on the filesystem or filesystem-redirector driver. Microsoft's filesystem drivers (e.g. NTFS) don't allow it, so probably your drive D: is a locally mounted filesystem, probably using a Microsoft driver. But it would help if you can provide the exact details. – Eryk Sun Aug 05 '17 at 05:45
  • @eryksun the file system is NTFS. I think I need to make little program that delete the file or use ubuntu live usb. Thanks. I wonder if you can give me some hint on what API should I use to delete this file? Thanks – Taeyun Aug 05 '17 at 06:14
  • if use `ZwDeleteFile` you can delete any file name(of course if it not in use, and you have permission) – RbMm Aug 05 '17 at 09:43
  • @RbMm, if the filename has a control character in it, `NtDeleteFile` for an NTFS volume fails with the status value `STATUS_OBJECT_NAME_INVALID`. While this system call is quicker than a normal delete-on-close operation (i.e. it doesn't require invoking the object manager to create a real `File` object), it still uses the normal path parsing to open the file (starting at `ObOpenObjectByName`), which ultimately depends on the filesystem driver to process an `IRP_MJ_CREATE` request. Microsoft's NTFS driver will fail this request; it stops parsing a path as soon as it sees an invalid character. – Eryk Sun Aug 05 '17 at 13:01
  • `DeleteFileW` won't work in this case for NTFS, even if used properly (i.e. deleting a file, not a directory). That's the normal route that calls `NtOpenFile` to get a File handle and then `NtSetInformationFile` to set the delete disposition on the filesystem's underlying file/link control block. It will fail at `NtOpenFile`. I don't know a direct way to delete a filename like this. I was only speculating that the NTFS driver may support some back-door IOCTL (i.e. via `DeviceIoControl`) to allow deleting or renaming a file with an invalid name. I just use Linux for this problem. – Eryk Sun Aug 05 '17 at 13:08
  • @eryksun - but how this file was created ? if it created with `NtCreateFile` (or shell over it) - it can be and deleted. may be name containing another characters - need call `ZwQueryDirectoryFile` for view names exactly as is and delete every file – RbMm Aug 05 '17 at 13:22
  • @RbMm, you can't create a file with a control character in its name on an NTFS volume mounted in Windows. `NtCreateFile` will fail because the filesystem driver fails the `IRP_MJ_CREATE` request. The NTFS driver only allows control characters in named streams, e.g. `"loader.bin:stream\r"`. I can only assume that the file was created in Linux (as I did when testing this) -- but not in the Windows 10 Linux subsystem, which will fail the `open` system call with `ENOENT` because ultimately it depends on the same NTFS driver. – Eryk Sun Aug 05 '17 at 13:31
  • @eryksun - because topic marked with *windows* keyword - i assume that file created inside windows. and if file created with some name - it can be and opened and deleted. if it created not under windows, and later disk mounted in windows - this is another question. so need delete file in os where he is created – RbMm Aug 05 '17 at 13:44

2 Answers2

0

this problem never happened to me but maybe using del /P directory you could be able to remove the file.

Example

Update

You could use a live Linux distro and delete the file you need.

Thanks

Community
  • 1
  • 1
Alberto
  • 446
  • 5
  • 14
  • It says: do you really want to delete file loader.bin? and I type "Y". Same name error occurs. Do I need to format this drive? or installing linux and delete from there may help? – Taeyun Aug 05 '17 at 04:56
  • Hi, I would say that format would be too much and install Linux maybe not necessary. Could you use a live distro, mount the filesystem and try removing the file? – Alberto Aug 05 '17 at 05:09
  • 1
    I installed ubuntu linux and now I am able to delete the file. Thanks. Please update the answer so I can select it. – Taeyun Aug 05 '17 at 09:08
0

Just to help any future lost folks who landed on this same page, this is what finally did it for me:

del "\\?\D:\IceDrive\Multimedia\Pictures\Events_Trips_and_Occasions\2022\2022 09 23 Bill Joel Concert "

Notice the space at the end. I could not delete that folder via any other means and it was messing up my Windows IceDrive sync.

gabeyww
  • 31
  • 4