Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete this kind of file using a reserved name?

Tags:

Hi for everyone in stackoverflow !

I'm looking for a workaround to how delete this kind of file using a reserved name such :

(nul, aux, com1, prn, etc...)

So, i get as output error :

The syntax of the file name, directory or volume incorrect.

@echo off
echo hello world>\\?\"%temp%\nul:nul"
pause
more<"%temp%\nul:nul"
pause
set /p MyVar=<"\\?\%temp%\nul:nul"
echo %MyVar%
Pause
Del "\\?\%temp%\nul:nul" /F
pause

I'm using this trick to store the password shown like in this code below so, i can set the password into this file and also, read from it, but i can't delete it.

@echo off
Title %~n0 with colors by Hackoo
Mode 50,5 & Color 0E
Setlocal EnableDelayedExpansion
:CreatePassword
Call :InputPassword "Please choose your password" pass1
Call :InputPassword "Please confirm your password" pass2
If !pass1!==!pass2! ( Goto:Good ) Else ( Goto:Bad )
::***********************************
:InputPassword
Cls
echo.
echo.
set "psCommand=powershell -Command "$pword = read-host '%1' -AsSecureString ; ^
    $BSTR=[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pword); ^
      [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)""
        for /f "usebackq delims=" %%p in (`%psCommand%`) do set %2=%%p
Goto :eof
::***********************************       
:Good
Cls
echo.
echo.
Call :Color 0B "                  Good password  " 1  
TimeOut /T 2 /NoBreak>nul
Call :Write_Info
Call :Collect_Info
echo Your password stored as : "!SavedPass!" without quotes
pause
Goto :Eof
::***********************************
:Bad
Cls
echo.
echo.
Call :Color 0C "            Wrong password try again " 1                
TimeOut /T 2 /NoBreak>nul
Goto :CreatePassword
::***********************************
:Color
for /F "delims=." %%a in ('"prompt $H. & for %%b in (1) do rem"') do set "BS=%%a"
set nL=%3
if not defined nL echo Requires third argument & Pause > nul & goto :Eof
if %3 == 0 (
    <nul set /p ".=%BS%">%2 & Findstr /V /A:%1 /R "^$" %2 nul & Del %2 2>&1
    goto :Eof
) else if %3 == 1 (
    echo %BS%>%2 & Findstr /V /A:%1 /R "^$" %2 nul & Del %2 2>&1
    goto :Eof
)
::***********************************
:Write_Info
(echo !Pass2!)>\\?\"%temp%\nul:nul"
Call :Color 0A "          Your password is set sucessfuly" 1 
::***********************************   
:Collect_Info
(set /P SavedPass=)<"\\?\%temp%\nul:nul"
goto :eof
::***********************************
like image 222
Hackoo Avatar asked Mar 25 '16 10:03

Hackoo


People also ask

How do I delete a folder name?

Open My Computer or Windows Explorer. We recommend you make sure the directory or folder is empty before proceeding, unless you intend to delete everything in it. Locate the file or folder you want to delete and right-click it. Choose the Delete option from the pop-up menu.


1 Answers

This worked for me:

del "\\.\%temp%\nul"

As Microsoft says in https://support.microsoft.com/en-us/kb/120716, you need to use a syntax which bypasses the check for reserved names.

like image 96
vitsoft Avatar answered Oct 12 '22 10:10

vitsoft