Filename codepage conversion

Posted on 2004-04-16
Last Modified: 2010-04-05
Situation: a trojan has created 100 folders on the desktop (Windows 98). The problem: it used some special characters.

Neither deleting, moving or renaming works - all attempts end in Windows error 1026 (which usually means network problems or not enough disk space, but that is not the case).

The only working way I found is using a command window, copying a folder name from the 'dir' results, and using 'rmdir' with that copied folder name. While this works, in the end I need a Windows program instead of manual instructions for this.

Using Windows.FindFirstFile,FindNextFile,FindClose (or the Delphi ones FindFirst, FindNext, FindClose) returns slighty different folder names (even pasting the copied 'dir' folder name into a Windows window does return a different name). Therefore I'ld say the problem is a different codepage. So I first tried to convert codepages from 437 - 850 - 1252 in all directions (later about a dozen different to no avail), but this didn't return any useful folder name.
I also tried a bunch of different removal procedures with all filename combinations - RmDir, RemoveDir, RemoveDirectory, DeleteFile, RenameFile, ShFileOperation - to no avail.

Well, maybe my codepage conversion isn't working (I convert to Unicode with one codepage and back with another). Does anyone know how to convert filename text from a dos box to valid Windows filename text (if the text contains codepage specific characters)? A conversion that would allow me to actually access the folder with RemoveDirectory?

PS: Accidently posted this in Programming as well... whoever solves this quickly will get points from both questions.
Question by:ccrdude
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3

Expert Comment

ID: 10848772
Use Far to Delete them ;)
you can download it fom here :

Author Comment

ID: 10853513
Thanks, but - as I said - I could already delete them from the command line. I want/need to delete them from my own code ;)

Expert Comment

ID: 10854629
In C the findfirst and findnext functions return the dos name of a file.
they are in dos.h header file.
In Delphi try these : FindFirstFile , FindNextFile , ... . I didn't test them in such situation.
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 10854850
Well, I appreciate your suggestion, but as you can read above, the name returned by those is not the one accepted by RmDir or RemoveDir. Works fine for file/folder names with only 'normal' characters, but not for those :(

Expert Comment

ID: 10858584
try this before using them : SetFileApisToANSI

SetFileApisToANSI :
  The SetFileApisToANSI function causes a set of Win32 file functions to use the ANSI character set code page. This function is useful for 8-bit console input and output operations

Accepted Solution

mbprogrammer earned 500 total points
ID: 10858612
or this one : SetFileApisToOEM .

Author Comment

ID: 10859888
Excellent! That was exactly what I was looking for, but couldn't find. Thank you!

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question