Delete file with special unicode char.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
BoQsc
Posts: 92
Joined: 30 Jun 2014 04:10

Delete file with special unicode char.

#1 Post by BoQsc » 05 Sep 2014 14:01

I searched on the internet and it seems i couldn't find solution. All i need is just delete file named 排名堡垒.txt using basic batch del command.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Delete file with special unicode char.

#2 Post by Squashman » 05 Sep 2014 14:30

Use the short file name.

Code: Select all

C:\BatchFiles\Kanji>dir /x
 Volume in drive C is 13_06P
 Volume Serial Number is 5AE4-90D0

 Directory of C:\BatchFiles\Kanji

09/05/2014  03:27 PM    <DIR>                       .
09/05/2014  03:27 PM    <DIR>                       ..
09/05/2014  03:27 PM                 0 C4B4~1.TXT   ????.txt
               1 File(s)              0 bytes
               2 Dir(s)  256,937,218,048 bytes free

C:\BatchFiles\Kanji>del C4B4~1.txt

C:\BatchFiles\Kanji>dir /x
 Volume in drive C is 13_06P
 Volume Serial Number is 5AE4-90D0

 Directory of C:\BatchFiles\Kanji

09/05/2014  03:29 PM    <DIR>                       .
09/05/2014  03:29 PM    <DIR>                       ..
               0 File(s)              0 bytes
               2 Dir(s)  256,937,218,048 bytes free

C:\BatchFiles\Kanji>

BoQsc
Posts: 92
Joined: 30 Jun 2014 04:10

Re: Delete file with special unicode char.

#3 Post by BoQsc » 06 Sep 2014 03:00

Thank you Squashman that worked great on txt files, but i seem to have trouble with .url by using the same method.
Batch file is asking for permissions when i want to delete url files. (access denied, look at the picture below)
Is there any way to bypass it and delete?

Strange thing i can rename it, but even after rename - i can't delete it using batch file.

Code: Select all

@echo off
rename 2014~1.url test.txt
del test.txt
pause


Image

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Delete file with special unicode char.

#4 Post by foxidrive » 06 Sep 2014 03:40

The page could have been open in Chrome or a text editor or something else (except it's a shortcut - not sure)
Reboot the PC and try it again without opening any programs.

When it is appropriate you can also use del *.url in the directory.

You can also boot up a Linux live cdrom and use the file manager in Linux to remove the file.

BoQsc
Posts: 92
Joined: 30 Jun 2014 04:10

Re: Delete file with special unicode char.

#5 Post by BoQsc » 06 Sep 2014 04:04

foxidrive, thank you for answer.
.url absolutely is shortcut to website.
del *.url is not working sadly, url file still here.
I restarted computer, and i'm sure no 3rd program is using the file.

I even tried del *.*
However, it also didn't help.
Both .url and renamed test.txt stayed in the folder. (all other files has been removed correctly)
I still have no idea how to remove it using batch so if anyone can give me any help, would be nice.

Also, i'm administrator of the computer, using Windows 8.1 x64 (but i think it is worthless information)

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Delete file with special unicode char.

#6 Post by foxidrive » 06 Sep 2014 04:11

foxidrive wrote:You can also boot up a Linux live cdrom and use the file manager in Linux to remove the file.


Download Ubuntu ISO image and write it to a disk and boot from that and use the file manager.

or for a smaller download you can download Puppy Linux and write it to a cdrom

http://www.puppylinux.com/download/index.html

BoQsc
Posts: 92
Joined: 30 Jun 2014 04:10

Re: Delete file with special unicode char.

#7 Post by BoQsc » 06 Sep 2014 04:15

foxidrive wrote:
foxidrive wrote:You can also boot up a Linux live cdrom and use the file manager in Linux to remove the file.


Download Ubuntu ISO image and write it to a disk and boot from that and use the file manager.

or for a smaller download you can download Puppy Linux and write it to a cdrom

http://www.puppylinux.com/download/index.html


Well, the faster way is just to drag and drop the file to recycle bin. :lol:

I can delete url files manualy. I just want to delete bunch of chinese url files automaticaly within one click. So that i didn't need to do that everytime and waste my time that much.

Also, thanks for answer.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Delete file with special unicode char.

#8 Post by foxidrive » 06 Sep 2014 04:22

BoQsc wrote:Well, the faster way is just to drag and drop the file to recycle bin. :lol:

I can delete url files manualy. I just want to delete bunch of chinese url files automaticaly within one click.

Then use this and right click on the batch file and run as administrator:

Code: Select all

@echo off
del *.url

You had at least me thinking that the filename had illegal characters in it which was stopping Windows from deleting it.

If that doesn't work then VBS can handle Unicode.

BoQsc
Posts: 92
Joined: 30 Jun 2014 04:10

Re: Delete file with special unicode char.

#9 Post by BoQsc » 06 Sep 2014 04:32

foxidrive Look what happen in windows 8.1 when simple batch file with del command is run as administrator: (look below post)
And by mistake i pressed Y, and it started to delete all files from C:\Windows\system32\ :shock:
But when i run without administration right - batch script is runing fine, except the url deletion, still can't do it.
Image
Last edited by BoQsc on 06 Sep 2014 04:37, edited 1 time in total.

npocmaka_
Posts: 517
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: Delete file with special unicode char.

#10 Post by npocmaka_ » 06 Sep 2014 04:34

I've tried WMIC query,jscript and filesystemObject , and wmi query through jscrit (didn't tried Shell.Application) - and didn't work.
What seems to work is deleting through jscript.net and list file where the file for deletion is recorded (and red with utf8 encoding):

Code: Select all

@if (@X)==(@Y) @end /****** silent line that start jscript comment ******

@echo off
del /q /f "%~n0.exe" && echo file deleted
::::::::::::::::::::::::::::::::::::
:::       compile the script    ::::
::::::::::::::::::::::::::::::::::::
setlocal
if exist "%~n0.exe" goto :skip_compilation


:: searching the latest installed .net framework
for /f "tokens=* delims=" %%v in ('dir /b /s /a:d /o:-n "%SystemRoot%\Microsoft.NET\Framework\v*"') do (
    if exist "%%v\jsc.exe" (
        rem :: the javascript.net compiler
        set "jsc=%%~dpsnfxv\jsc.exe"
        goto :break_loop
    )
)
echo jsc.exe not found && exit /b 0
:break_loop



call %jsc% /nologo /out:"%~n0.exe" "%~dpsfnx0"
::::::::::::::::::::::::::::::::::::
:::       end of compilation    ::::
::::::::::::::::::::::::::::::::::::
:skip_compilation

"%~n0.exe"

exit /b 0


****** end of jscript comment ******/
import System;
import System.IO;
import System.Text;
 
 //F:\\scriptests\\list.txt has a single line containing F:\scriptests\排名堡垒.txt
 var  readText = File.ReadAllText("F:\\scriptests\\list.txt",Encoding.UTF8);
 Console.Write( readText);
File.Delete(readText);


I think you can go on from here and modify the script above to be suitable for you .Hope this helps.

Probably is still possible with windows script host or WMI but I didnt found a way.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Delete file with special unicode char.

#11 Post by foxidrive » 06 Sep 2014 04:36

That's a problem - but you wrote *.* instead of *.url
If it was *.url then it wouldn't have mattered.

This should get around the problem with the working directory.

Code: Select all

@echo off
del "%~dp0\*.url"
pause

BoQsc
Posts: 92
Joined: 30 Jun 2014 04:10

Re: Delete file with special unicode char.

#12 Post by BoQsc » 06 Sep 2014 04:47

npocmaka_ Thank you, i'm going to take a look at it later on.

foxidrive wrote:That's a problem - but you wrote *.* instead of *.url
If it was *.url then it wouldn't have mattered.
Yep, i know that, it's my silly mistake.

foxidrive wrote:This should get around the problem with the working directory.

Code: Select all

@echo off
del "%~dp0\*.url"
pause
Here is what i get (the same error like without administrator rights) i have no idea what's wrong (i'm 100% administrator, i even can delete system files tho :lol: ):
Image

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Delete file with special unicode char.

#13 Post by foxidrive » 06 Sep 2014 04:59

Try this - again by right clicking and run as administrator.

Code: Select all

@echo off
del "%~dp0\*.url" /a /f
pause


I'm assuming that the cmd prompt can handle these files - I don't have any to test with.

aGerman
Expert
Posts: 4744
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Delete file with special unicode char.

#14 Post by aGerman » 06 Sep 2014 05:09

%~dp0 contains a trailing back slash. Maybe you should remove it and use "%~dp0*.url" instead. Just a guess though.

Regards
aGerman

BoQsc
Posts: 92
Joined: 30 Jun 2014 04:10

Re: Delete file with special unicode char.

#15 Post by BoQsc » 06 Sep 2014 05:37

foxidrive, you are my hero! It works finaly. And it looks like with your code arguments there is no required for administrator privilegies.
Here is the example file i used for testing (if anyone need it later on): http://wikisend.com/download/229684/2014%E5%B9%B4%E5%85%A8%E9%83%A8%E7%83%AD%E9%97%A8%E5%8D%95%E6%9C%BA%E6%B8%B8%E6%88%8F%E5%8F%8A%E6%B1%89%E5%8C%96%E4%B8%8B%E8%BD%BD.url

The batch script that worked is here:

Code: Select all

@echo off
del "%~dp0\*.url" /a /f
pause


And this is working test with specific file name:

Code: Select all

@echo off
dir /x
pause
del "%~dp0\2014~1.URL" /a /f
pause


No need to run as administrator for both.

Thanks to everyone. :)

Post Reply