I am trying not to delete internet shortcuts using c#
the code is like this

static void Main(string[] args)
{
            string path = @"C:\KOINA_ARXEIA";
            string[] folders;
            folders = System.IO.Directory.GetDirectories(path, "*", System.IO.SearchOption.AllDirectories);
            foreach (string folder in folders)
            {
                Console.WriteLine("Getting files for Directory:{0}\n", folder);
                string[] files = System.IO.Directory.GetFiles(folder);


                foreach (string file in files)
                {
                    string fileExtension = System.IO.Path.GetExtension(file);
                    if (fileExtension != ".url")
                    {
                        Console.WriteLine("File {0} is  url link, deleting it\n", file);
                        System.IO.File.Delete(file);
                    }
                }
            }
}

but they are deleted....the files are in greek words and url extension is not visible
I am using Windows Xp Sp3 pro

Recommended Answers

All 3 Replies

I don't understand. You say you are trying not to delete the files, but you are deleting: System.IO.File.Delete(file); .

When you say the url extension is not visible, what do you mean?

My bad syntax...sorry how not to delete.....I solved it......As u can see in my if statemt i use != to check wether something isn't an internet shortcut and if it's not...i delete it...But ok now...i retyped my if statement like this

if (System.IO.Path.GetExtesnion(file) != ".url") and worked like a charm....ty...

:D It happens to us all. Please mark the thread as solved then.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.