Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your help!

We need 7 developers from Canada and 18 more from Australia to help us complete a research survey.

Support our site by taking a quick sponsored survey and win a chance at a $50 Amazon gift card. Click here to get started!


Enerjak

Member Since 08 Nov 2007
Offline Last Active Aug 11 2015 06:41 AM

Posts I've Made

In Topic: Can someome please tell me why this crashes?

11 August 2015 - 04:24 AM

If you happen to have a cygwin shell installed (e.g. if you installed git) you could also just use:

find /c/Users/admin/Documents -name "*.mp4" -exec basename {} \; > video_filenames.txt

Maybe someone can translate that to the Windows cmd equivalent.

Thanks for responding also, oh herald of doom and gloom. 


In Topic: Can someome please tell me why this crashes?

11 August 2015 - 04:23 AM

var files = Directory.GetFiles("C:/Users/admin/Documents", "*.mp4");
for (int i=0; i<files.Length; ++i)
    files[i] = string.Format("{0}: {1}", i+1, files[i]);
File.WriteAllLines("video_filenames.txt", files);
Or, if you're feeling crazy:
 
File.WriteAllLines("video_filenames.txt", Directory.GetFiles("C:/Users/admin/Documents", "*.mp4").Select((x,i) => string.Format("{0}: {1}", i+1, x)));

Thanks, man. That helped a lot. I was going to use C++ but thought using C# would have been far easier to do so. I was right, just was making it complicated I guess.


In Topic: Can someome please tell me why this crashes?

10 August 2015 - 08:36 PM

 

My guess (haven't tried running the code) is that you're leaking the file-handle, calling File.Create(), and then later calling File.WriteAllText().  File.Create() will create an empty file, and return you the FileStream pointing to it.  File.WriteAllText() will try to again create the file, which it will not be able to do, because the FileStream has not been Close()'d or Dispose()'d properly.

 

There are a number of things wrong with what you're doing here, though, and it could be written more succinctly like so:

var files= Directory.GetFiles("C:/Users/admin/Documents", "*.mp4");
File.AppendAllLines("video_filenames.txt", files);

It couldn't have been that easy......could it? two lines of code and all my problems are solved? nice. Though What if I wanted to add the number next to the file name to keep track of how many there are?


In Topic: Some errors in my vector3 class that seem kind of odd.

30 April 2015 - 09:47 PM

I've gotten so many answers, not sure which one is the right one.


In Topic: Checking the equality of objects in C#

14 January 2015 - 09:28 PM

Well, after some trial and error and taking the advice of Madhed into consideration, I've managed to fix it. turns out? I forget to set a value in the "addToList" method of the main form. Yup, it's always the simplest stuff that gets ya.


PARTNERS