• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 240
  • Last Modified:

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.
0
Samuel-AMC
Asked:
Samuel-AMC
  • 28
  • 15
  • 9
  • +1
3 Solutions
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
Perform a
   dir /x C:\Documents and Settings\All Users\
and see what the short name is. Probably it is something like
   C:\Docume~1\AllUse~1\MenuIn~1
You can then use that short name. Note that the tilde and number are always at the end of a name.
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
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.
0
 
mcsweenSr. Network AdministratorCommented:
To type the ú you hold Alt and press 0250 on the number pad then release Alt.

http://symbolcodes.tlt.psu.edu/bylanguage/spanish.html
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
Samuel-AMCAuthor Commented:
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.
0
 
mcsweenSr. Network AdministratorCommented:
If you enter the correct symbol in the path in your batch file it will work.  For example:

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

Open in new window


Alt+0250 types that character on an English system.
0
 
Samuel-AMCAuthor Commented:
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.
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
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?
0
 
mcsweenSr. Network AdministratorCommented:
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.
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
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.
0
 
mcsweenSr. Network AdministratorCommented:
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.
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
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.
0
 
Samuel-AMCAuthor Commented:
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.
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
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

0
 
Samuel-AMCAuthor Commented:
Say I'm in command prompt, how exactly is it that I have to use the Tab key?
0
 
Samuel-AMCAuthor Commented:
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."
0
 
Samuel-AMCAuthor Commented:
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.
0
 
Samuel-AMCAuthor Commented:
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
0
 
Samuel-AMCAuthor Commented:
Except for this command: cd Men* But I get the same thing Menú Inicio
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
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.
0
 
Samuel-AMCAuthor Commented:
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.
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
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.
0
 
Samuel-AMCAuthor Commented:
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.
0
 
Samuel-AMCAuthor Commented:
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".
0
 
Samuel-AMCAuthor Commented:
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.
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
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.
0
 
Samuel-AMCAuthor Commented:
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.
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
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.
0
 
Samuel-AMCAuthor Commented:
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.
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
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).
0
 
Samuel-AMCAuthor Commented:
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.
0
 
Samuel-AMCAuthor Commented:
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.
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
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).
0
 
Samuel-AMCAuthor Commented:
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.
0
 
Bill PrewCommented:
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
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
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

0
 
Bill PrewCommented:
Qlemo,

I went after the start menu (Common Start Menu) since the original question indicated a desire to delete more than one folder from that location. So I guess it depends on what is really needed.

~bp
0
 
Samuel-AMCAuthor Commented:
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.
0
 
Samuel-AMCAuthor Commented:
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.
Example 1Now 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
Example 2If 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."
Example 3In 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.
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
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.
0
 
Bill PrewCommented:
@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
0
 
Samuel-AMCAuthor Commented:
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.
0
 
Samuel-AMCAuthor Commented:
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.
0
 
Bill PrewCommented:
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
0
 
Samuel-AMCAuthor Commented:
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.
0
 
Samuel-AMCAuthor Commented:
Okay Bill, mission accomplished...
I have two examples, a screenshot and a code text, take a look:
Screenshot
! 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

0
 
Bill PrewCommented:
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
0
 
Samuel-AMCAuthor Commented:
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"
0
 
Bill PrewCommented:
In my code, change:

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

to:

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

~bp
0
 
Samuel-AMCAuthor Commented:
No Bill, it did not work, take a look:
The system can not find the path specified.
It did not work
0
 
Samuel-AMCAuthor Commented:
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"
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
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.
0
 
Bill PrewCommented:
What is the full path to the folder you are trying to delete?

~bp
0
 
Samuel-AMCAuthor Commented:
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"
0
 
Bill PrewCommented:
Okay, so be it.

~bp
0
 
Samuel-AMCAuthor Commented:
Thank you for all your help bill
0
 
Bill PrewCommented:
Welcome.

~bp
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

  • 28
  • 15
  • 9
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now