Avatar of Samuel-AMC
Samuel-AMC

asked on 

Batch deliting dirs - parsing symbols

Hello Everyone,

I'm trying to delete some folders with special characters, I used to do this, but I forgot,
The folders are locate here: C:\Documents and Settings\All Users\Menú Inicio\Programs.
The problem is here "Menú Inicio" so I tried "Men~1 Inicio" but is not working.
Example: RMDIR "C:\Documents and Settings\All Users\Menú Inicio\Programs"
Any suggestion will be appreciate, thanks.

NOTE: I'm not trying to delete the folder "Menú Inicio"
I'm trying to delete folders that are inside that folder.
Windows Batch

Avatar of undefined
Last Comment
Bill Prew
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Qlemo
Qlemo
Flag of Germany image

You can also use filename completion (usually), that is type the beginning of the name, then press TAB until you get the correct file name, then add a slash and type the beginning of the subfolder, etc.
Avatar of Bradley Fox
Bradley Fox
Flag of United States of America image

To type the ú you hold Alt and press 0250 on the number pad then release Alt.

http://symbolcodes.tlt.psu.edu/bylanguage/spanish.html
Avatar of Samuel-AMC
Samuel-AMC

ASKER

Hi Qlemo, this part "MenuIn~1" look like the command I used to use,
but honestly I can't remember, I just tried your suggestion and this is
what I get...

I tried: "dir /x C:\Documents and Settings\All Users\" but I get something
like: "The system can not find the file specified".

Then I tried adding this part to my batch "MenuIn~1" but didn't delete none.

Hi mcsween, I don't know how to say this, but what I need is a way to delete a
folder which have a spanish character that an english batch is having problems
parsing that character, thanks.
SOLUTION
Avatar of Bradley Fox
Bradley Fox
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of Samuel-AMC
Samuel-AMC

ASKER

mcsween, the "del" in my case here it only delete files but not folders.

Qlemo, let me add an extra info, right now in this computer, the one I'm using,
Which is enlgish windows, if I create a folder in the desktop and I name it: Menu
and the use: RMDIR "C:\Users\Documents\Desktop\MEN~1" I'm able to delete it,
But if I try to use this method on that computer for some reason it does not work.
Avatar of Qlemo
Qlemo
Flag of Germany image

With XP, the "Documents and Settings" name depends on your OS language, and might differ for Spanish OS (and I would expect it to do). On Vista and above, the (user specific) folder is "Users" instead (and not translated), and the "All Users" is "C:\ProgramData". Try
  dir /x %AllUsersProfile%
that should work at all times.

If you are in a batch file, and you want to have that running reliably on any system, it's more complex, as we need to determine the folder name dynamically. So, is this a one-time action?
Avatar of Bradley Fox
Bradley Fox
Flag of United States of America image

I don't understand the issue; the del command is for files; if you wanted to remove the directory you would use rmdir.  Just type the command like you would without a special char, except when you get to the accented u just press Alt+0250

This command deletes somefile.txt in that folder

del "C:\Documents and Settings\All Users\Menú Inicio\Programs\somefile.txt" /q

Open in new window

Make sure you are wrapping your path in quotes ("") because the path has spaces.
Avatar of Qlemo
Qlemo
Flag of Germany image

mcsween,
characters outside of the basic code page (any ASCII char above 127) can be interpreted differently on the commandline and in e.g. notepad. So if you use an editor to enter that character, it might still not work in cmd.exe.
Avatar of Bradley Fox
Bradley Fox
Flag of United States of America image

Actually, only ASCII codes 1-37 and 127 can be interpreted differently as they can also be control characters.  This typically only affects printing and terminal applications like puTTy or TN3270.
Avatar of Qlemo
Qlemo
Flag of Germany image

Wrong. We use Umlauts, and they are different, unless I change my code page with chcp. The same applies to e.g. Czech or Hungarian special characters. In most cases, Windows uses code page 1252 (or variants on Eastern Europe). cmd.exe uses 437, 850, or variants, depending on the OS language.
Avatar of Samuel-AMC
Samuel-AMC

ASKER

Qlemo, yes it is Windows XP OS Spanish language,
So I tried: "dir /x %AllUsersProfile%" but still get this:
El sistema no puede hallar el archivo especificado.
Which means: The system can not find the file specified.

But the nearest character you gave me is this: MenuIn~1
From what I remember something like this is what works,
But in this case is not working, there is something missing,
or there is something different that we need to add.
Avatar of Qlemo
Qlemo
Flag of Germany image

The dir command I gave you has to work for all (recent) OS. Very strange.
Currently I do not have access to a Spanish OS, so can't look myself, but I'm pretty sure I'm right. Did you try the TAB? You can also use successive CD commands:
cd C:\Do*
cd All*
cd Men*
rd /s /q Programs

Open in new window

Avatar of Samuel-AMC
Samuel-AMC

ASKER

Say I'm in command prompt, how exactly is it that I have to use the Tab key?
Avatar of Samuel-AMC
Samuel-AMC

ASKER

Let me specify again, what I want is to delete this directory:
"C:\Documents and Settings\All Users\Menú Inicio\Programas\Folder"
using the command RMDIR from my batch file, but if I tried just like that
the way it is, the batch does not delete anything. and if I add a PAUSE at the
end of the batch I can see the error message:
"El sistema no puede hallar el archivo especificado."
Which means: "The system can not find the file specified."
Avatar of Samuel-AMC
Samuel-AMC

ASKER

I think that I won't be able to run this test :-(
I have to give this computer to the owner today.
I wish I could do something about. Please help me guys.
Avatar of Samuel-AMC
Samuel-AMC

ASKER

Qlemo I tried all the commands, but I get an error saying that,
Thats an invalid name giving to the folders or diretories.

cd C:\Do*
cd All*
cd Men*
rd /s /q Programs
Avatar of Samuel-AMC
Samuel-AMC

ASKER

Except for this command: cd Men* But I get the same thing Menú Inicio
Avatar of Qlemo
Qlemo
Flag of Germany image

When you are there (in the Menú Incio folder), the rd (same as rmdir) should work! It does no longer care about special characters in the path.

The file/folder name completion works like this:
You type the beginning part of the name you want to have in the commandline, and then press TAB (I already described that). E.g. you type
   cd Men
then press TAB. If there is a folder in the current folder beginning with Men, it will add what it found, and you can press TAB several times if there are more than one hit.
Avatar of Samuel-AMC
Samuel-AMC

ASKER

Qlemo, I understand now, but you know whats the problem? ...I tried,
But since this machine have Widnows XP OS in spanish, what ever I do,
What ever I try I get everything back in the current language installed.
Avatar of Qlemo
Qlemo
Flag of Germany image

On the SAME system you have that non-ASCII characters in file names, and as long as you do not try to copy paste what you see, it should still work - the content you get is what is stored. On copying the name, however, there might be convertions, and characters get lost or changed.
You can also try to enter
   chcp 1252
in the cmd window before you do anything. That should allow for most of the characters needed (not sure about something like [~n], though), and switch off the old, command.com compatible handling of code pages.
Avatar of Samuel-AMC
Samuel-AMC

ASKER

Long time ago when I first got into this situation, serching in Google I found a
solution, but I forgot, the solution was something like your first post MenuIn~1
but did not have the ~1 instead it was something else, but I can't remember.
Avatar of Samuel-AMC
Samuel-AMC

ASKER

Qlemo, when you mentioned the about trying to get the symbols in cmd
by using the tab key, I got that point, but I thought that by doing that I was
going to be able to see how cmd turn Menú Inicio into the real name which
could be MenuIn1 or MenuIn~1 or what ever other name is, but instead it
gived me the same name which is "Menú Inicio".
Avatar of Samuel-AMC
Samuel-AMC

ASKER

Doing some research I found these examples: "MENUIN~1" and also "MENINI~1"
But still nothing, the folders example that I tried to delete does not get deleted.
Avatar of Qlemo
Qlemo
Flag of Germany image

That is correct. The filename completion works for the real name. What you name "real" name is a 8.3 emulation of the name. You can't see that one with filename completion. And it wouldn't be of much use anyway. Imagine following (hypothetical) folders:
   C:\Documents and Settings\All Users\Menú Indirect
   C:\Documents and Settings\All Users\Menú Inicio
The first one would be named  MenuIn~1, the second MenuIn~2. Using MenuIn~1 is dangerous.
Avatar of Samuel-AMC
Samuel-AMC

ASKER

Sorry to say this, but at least for me it does not make sense,
I'm not referring to you Qlemo, I am referring to the issue I'm having.
But let me tell you something, for example in a computer with english os if you try to
view any dir from cmd you'll see that cmd turn those names into some weird name...
but if you try the same in a computer with spanish os you'll see that is not the same.

Let me put it this way, if I go to cmd and try to view the folders located in All Users,
I see the same thing, what I mean is that they look just the same, no symbols no nothing.
For this I go to cmd and type: "cd C:\Documents and Settings\All Users" then type: "dir"
and I get what you see here:
Documentos
Escritorio
Favoritos
Menu Inicio
Now the as for trying to delete a folder that is inside of the folder "Menu inicio" I have
tried deleting them using the same name without changing anything, but don't work.

RMDIR "C:\Documents and Settings\All Users\Menú Inicio\Programas\Folder"

RMDIR "C:\Documents and Settings\All Users\MENUIN~1\Programas\Folder"

RMDIR "C:\Documents and Settings\All Users\MENINI~1\Programas\Folder"

I have tried many ways but none of these seem to work.

The problem here is that cmd is having difficulty recognizing "Menú Inicio".
And I almost forgot to say this, the command MENINI~1
I think is from a portuguese XP OS.
Avatar of Qlemo
Qlemo
Flag of Germany image

Something is screwed up. The installation language of the OS determines which folder names are created (locally) pre-Vista. That might be different if there are roaming profiles - stored on the server, but honestly, I don't know that.

On English XP, you never should see something like "Documentos", "Escritorio" etc.

As that all does not make sense to me, I cannot give more advice. The filename completion method always works, however.
Avatar of Samuel-AMC
Samuel-AMC

ASKER

Qlemo wrote:
"Something is screwed up. The installation language of the OS determines which
folder names are created (locally) pre-Vista."

For what I believe there is nothing screw up on this spanish os.

Qlemo wrote:
"That might be different if there are roaming profiles - stored on the server,
but honestly, I don't know that.

No, there are not roaming profiles, there is only one account in the system.

Qlemo wrote:
"On English XP, you never should see something like "Documentos", "Escritorio" etc."

Of course not, spanish is spanish, and english is english, and those words are spanish.

Thanks anyway Qlemo, but I have to keep searching for the answer,
which I know there is a solution for this task.
Avatar of Qlemo
Qlemo
Flag of Germany image

You are confusing me by changing the language and context with every sentence. And then look at
But let me tell you something, for example in a computer with english os if you try to view any dir from cmd you'll see that cmd turn those names into some weird name...
- that is not true, on English OS you have no weird names. No wonder I can't get sense out of it.

Do you want a generic method of how to delete that folder? The answer is "You can't do that". Because, as I explained, English XP uses English folder names, Spanish uses Spanish, aso. You will NOT be able to handle that generic. Maybe you are trying to collect all reasonable alternatives of the Start Menu entry, but that won't work very well unless you set the code page in the batch to something well known (like my already mentioned  chcp 1252), which is almost the same as the character set you use in Notepad in (West & Middle) Europe.

If you are on a Spanish OS all the time, you can easily hard-code the (full!) name. Don't use the short name, it is not unique (and I have explained why in a prior comment).
Avatar of Samuel-AMC
Samuel-AMC

ASKER

Hey man, I appreciate that you are helping me with this question...
But why you guys always find an excuse to get out my questions ???

"that is not true, on English OS you have no weird names.
No wonder I can't get sense out of it."

What do you meant with: "No wonder I can't get sense out of it. ???
I mentioned from the very beginning what I wanted.

"Do you want a generic method of how to delete that folder?
The answer is "You can't do that".

I done it before, so there is a way to do it from a batch file, but I forgot.
if you don't know how thats fine body, not a problem, but don't tell me that
I screw things up okay? ...my question in conclution is very simple to understand,
and by saying that it is very simple to understand, that doens't meant that is an
easy task, but there is a way to delete, create, and so on from a batch file.
Avatar of Samuel-AMC
Samuel-AMC

ASKER

When I find the solution I will share here with you, I would even record the screen
so you can get to see it that it is possible to delete that folder on that root or path
using a batch file.
Avatar of Qlemo
Qlemo
Flag of Germany image

No-one ever told you that you can't delete this specific folder. But it is not reliable to use a 8.3 shortcut name on any other PC, same or other language. I have shown you several ways how you can help yourself on a specific PC, but you dismissed all as not working.

Believe me, I have done that several times on Czech, Polish, Hungarian, Chinese, English, Spanish, Portugese, German (and certainly some more) OS, and know how to do it. E.g. using the DIR output, and copy paste it in the same cmd window will always work. The same applies for names got by filename completion. That is because those output will use exactly the same character set then the command line.

And in regard of the "no wonder ..." statement, please read the quote above again - you are telling me there are weird characters on English OS, but they must not be there, as the corresponding folder is called Start Menu, and nothing else. Obviously you try to express something else, which does not find its way into the sentence. Remember that I can see only what you write, nothing more, and do not want to second guess what you really try to say (because I will be even more wrong then most likely).
Avatar of Samuel-AMC
Samuel-AMC

ASKER

Qlemo, I did not dismissed all as not working, I only told you the true.
otherwise this question would already be closed long ago don't you think.
I tried every single way that you suggested me to follow but no luck.
Avatar of Bill Prew
Bill Prew

Here is another approach to try.  It will query the registry to find the path to the base folder, and then you can delete any desired subfolders.

@echo off
setlocal

REM Define constants
set Key=HKLM\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
set Value=Common Start Menu

REM Query the registry for the key and value we need
for /F "tokens=4*" %%A in ('reg query "%Key%" /V "%Value%" 2^>nul ^|findstr /I /L /C:"REG_"') do call set MyDir=%%~B
rmdir /S /Q "%MyDir%\Programs"

Open in new window

~bp
Avatar of Qlemo
Qlemo
Flag of Germany image

Good idea, Bill, but even "Programs" could be different (Programme, Programas, ...). The correct Shell Folder value is "Common Programs" instead of "Common Start Menu", and the rmdir needs to get applied to exactly that folder (I've also replaced findstr with find because it is more "light-weighted"):
@echo off
setlocal

REM Define constants
set Key=HKLM\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
set Value=Common Programs

REM Query the registry for the key and value we need
for /F "tokens=4*" %%A in ('reg query "%Key%" /V "%Value%" 2^>nul ^|find /I "REG_"') do call set MyDir=%%~B
rmdir /S /Q "%MyDir%"

Open in new window

SOLUTION
Avatar of Bill Prew
Bill Prew

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of Samuel-AMC
Samuel-AMC

ASKER

Guys, the computer which I was working on, and had this issue with, the owner
picked up before I get to try or test the code posted by bill, but I got a hold of
an spanish os which I will be installing tonight and finally be able to test bill code.
Just give me few hours, thanks for your help.

but believe it or not, few years ago I was able to delete and create folders in the
"Menu Inicio" folder. And I want to correct something, I never said I wanted to
delete the "Menu Inicio" folder, what I said is that I wanted to delete folders that
were inside of that folder.
Avatar of Samuel-AMC
Samuel-AMC

ASKER

Hello guys, I'm back, yeah I know it's been four days and could not answer back,
But thats because I had been busy looking for the spanish os, had gotten one, but
it came out with errors, but finally got one today that really works.
So I'm bringing you the answer to my solution :-)

And with all due respect, but the batch-reg code from bill does not do the trick.

There are many things I want to explain in case someone search for this answer.
If your machine have XP OS in enlgish and decide to install XP OS in spanish then,
this won't work, it happened to me, I tried because I really wanted to run the test.

Now this is what really worked for me...
RMDIR "C:\Documents and Settings\%UserName%\MENINI~1\Programas\delete2"
The "delete2" is a folder I created to test the code, and it does work, it deleted it.

Now the one I was trying and could not make work is this:
RMDIR "C:\Documents and Settings\All Users\MENUIN~1\Programas\delete2"

So it is not "MENUIN~1" the correct command is "MENINI~1"
In this screenshot I run a test of the two commands, and MENUIN~1 did not worked.
User generated imageNow the only thing that I just noticed is that folders like the one in this screenshot
cannot be deleted, don't know why, maybe because is an aministrative directorie?
the name of the folder was some other name, but I renamed to delete1
User generated imageIf I try to run the batch code to delete it I get the following error:
"El sistema no puede hallar el archivo especificado." which means:
"The system can not find the file specified."
User generated imageIn conclution the answer to the puzzle is "MENINI~1"
Like I said, problem here was that cmd is had difficulty recognizing "Menú Inicio".
and that is why Menú Inicio have to be turn into MENINI~1 but not MENUIN~1.
I feel good, comfortable to have found the solution :-)

But I must admit that you have helped me, so I would like to split points even if
there was not an answer. thank you guys.
Avatar of Qlemo
Qlemo
Flag of Germany image

I've told you that the short name is not reliable. It is almost impossible for us to predict it, without having a similar system.
Avatar of Bill Prew
Bill Prew

@Samuel-AMC

==> And with all due respect, but the batch-reg code from bill does not do the trick.

Care to expand on that, what does it do, or not do, that is not right?

~bp
Avatar of Samuel-AMC
Samuel-AMC

ASKER

Yeah I understand Qlemo, in my case I had to install xp spanish twice to run the test.
It is hard to try to generate a test in a machine that does not have such dir root path.
Avatar of Samuel-AMC
Samuel-AMC

ASKER

Bill, me too, I really wanted to find out what could the code do, but I tried and did nothing.
Thats the first thing that I tried before anything but did nothing, so I moved to step 2.
Thanks anyway Bill.
Avatar of Bill Prew
Bill Prew

Just for curiosity, do the following at a command line, and paste the output up here please.

reg query "HKLM\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders"

~bp
Avatar of Samuel-AMC
Samuel-AMC

ASKER

Yes Bill, give me a minute, good thing I still have it :-) cuz I was gonna format
the hdd again, as I installed just to run that test, so give me a minute and see
what we get.
Avatar of Samuel-AMC
Samuel-AMC

ASKER

Okay Bill, mission accomplished...
I have two examples, a screenshot and a code text, take a look:
User generated image
! REG.EXE VERSION 3.0

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Explorer\User ShellFolders
    Common Desktop      REG_EXPAND_SZ   %ALLUSERSPROFILE%\Escritorio
    Common Start Menu   REG_EXPAND_SZ   %ALLUSERSPROFILE%\Menú Inicio
    Common Programs     REG_EXPAND_SZ   %ALLUSERSPROFILE%\Menú Inicio\Programas
    Common Startup      REG_EXPAND_SZ   %ALLUSERSPROFILE%\Menú Inicio\Programas\Inicio
    Common AppData      REG_EXPAND_SZ   %ALLUSERSPROFILE%\Datos de programa
    Common Templates    REG_EXPAND_SZ   %ALLUSERSPROFILE%\Plantillas
    Common Favorites    REG_EXPAND_SZ   %ALLUSERSPROFILE%\Favoritos
    Common Documents    REG_EXPAND_SZ   %ALLUSERSPROFILE%\Documentos

Open in new window

Avatar of Bill Prew
Bill Prew

Based on that you would need to do:

@echo off
setlocal

REM Define constants
set Key=HKLM\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
set Value=Common Start Menu

REM Query the registry for the key and value we need
for /F "tokens=4*" %%A in ('reg query "%Key%" /V "%Value%" 2^>nul ^|findstr /I /L /C:"REG_"') do call set MyDir=%%~B
rmdir /S /Q "%MyDir%\Programas"

Open in new window

~bp
Avatar of Samuel-AMC
Samuel-AMC

ASKER

Bill, but does this script delete any folder on that root or path directory?
I mean here C:\Documents and Settings\%UserName%\Menu Inicio\Programas\DirToDel
And where does the name of the folder to be deleted goes?

This line of code do the trick:
RMDIR "C:\Documents and Settings\%UserName%\MENINI~1\Programas\DirToDel"
Avatar of Bill Prew
Bill Prew

In my code, change:

rmdir /S /Q "%MyDir%\Programas"

to:

rmdir /S /Q "%MyDir%\Programas\DirToDel"

~bp
Avatar of Samuel-AMC
Samuel-AMC

ASKER

No Bill, it did not work, take a look:
The system can not find the path specified.
User generated image
Avatar of Samuel-AMC
Samuel-AMC

ASKER

Bill, one thing that I would like to mention is that I changed
FROM: rmdir /S /Q "%MyDir%\Programas\DirToDel"
TO:      rmdir /S /Q "%MyDir%\DirToDel"
Avatar of Qlemo
Qlemo
Flag of Germany image

The reg part you posted refers to the All Users profile, and that is where Bill's code is taking the values from, but the folder is in the user's profile now.
You would have to use following reg paths:
set Key=HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
set Value=Start Menu

Open in new window

or move the folder to delete to the All Users profile.
Avatar of Bill Prew
Bill Prew

What is the full path to the folder you are trying to delete?

~bp
Avatar of Samuel-AMC
Samuel-AMC

ASKER

This is the full path to the folder, any of these:
C:\Documents and Settings\%UserName%\Menú Inicio\DirToDel
C:\Documents and Settings\%UserName%\Menú Inicio\Programas\DirToDel
Sorry bill, but definitely does not work.

The only one that works for me is this:
RMDIR "C:\Documents and Settings\%UserName%\MENINI~1\Programas\DirToDel"
Avatar of Bill Prew
Bill Prew

Okay, so be it.

~bp
Avatar of Samuel-AMC
Samuel-AMC

ASKER

Thank you for all your help bill
Avatar of Bill Prew
Bill Prew

Welcome.

~bp
Windows Batch
Windows Batch

Batch files are text files containing a script of commands that are executed by the command interpreter on DOS, OS/2 and Windows systems. Most commonly, they are used to perform a series of functions that are repeated -- copying a set of files created daily with one step, for example.

13K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo