• Beginners Code
    3 replies, posted
Hi, I`m just wondering if it`s of any use of asking anyone here to help a total rookie with his first project? I have watched and read quite a bit already, and have bits of semi working code for my project. Basically it`s a file operator app, 1. It should open a file(A.*) read some bytes store them, //a GUID if you will, i.e FFE742A19139AF10 2. Open another folder and look for a file who`s name partially contains the bytes from the file (A), ffe742a19139af10e1a452b7b4a987a3 firstMip2.chunk if the file is present make a copy of it and save to file`s (A.*) folder. I have got the 1st part working, now my problem is how do I setup search for a file using that GUID. Here`s the code [url]http://pastebin.com/KjVgUFv0[/url] Anyone could help me with this? Or maybe point me to an existing project that I could learn from? Thanks
If I understand what you want to do correctly, say you had these two string variables: fileName = 'ffe742a19139af10e1a452b7b4a987a3 firstMip2.chunk' and partialGUID = 'FFE742A19139AF10' You could say fileName.Contains(partialGUID.ToLower()) which would return true if the filename contained your string. If your main concern finding the file names in a folder, you can do something similar this: [code] string partialGUID = "FFE742A19139AF10" string filepath = **Your saved files directory path**; string[] files = Directory.GetFiles(filepath, "*.txt", SearchOption.AllDirectories); foreach (string s in files) { if (s.Contains(partialGUID.ToLower()) { File.Copy(s, **Target file/location**); } }[/code] Also remember that Google/MSDN are a coders best friend. I got most of the above code just by searching "c# get all files in a folder"
s.ToLower().Contains(...), Directory.GetFiles(...) gives the stored capitalisation.
Thanks guys I`ve most of it working, now I need to expand the features. Thanks again guys.
Sorry, you need to Log In to post a reply to this thread.