RSS Forums RSS
Please support our C# advertiser: Programming Forums

Quick directory question

Join Date: Jul 2005
Location: FL.
Posts: 1,536
Reputation: tayspen is on a distinguished road 
Rep Power: 7
Solved Threads: 98
Colleague
tayspen's Avatar
tayspen tayspen is offline Offline
<Insert title here>

Re: Quick directory question

  #9  
Sep 13th, 2005
oks o i set this

public void Read()
        {
            File.SetAttributes(textBox1.Text + "\\iPod_Control\\Music", FileAttributes.Normal);
            // Read the 128 byte ID3 tag into a byte array
            FileStream oFileStream;
            oFileStream = new FileStream(this.filename, FileMode.Open);
            byte[] bBuffer = new byte[128];
            oFileStream.Seek(-128, SeekOrigin.End);
            oFileStream.Read(bBuffer, 0, 128);
            oFileStream.Close();

            // Convert the Byte Array to a String
            Encoding instEncoding = new ASCIIEncoding();   // NB: Encoding is an Abstract class
            string id3Tag = instEncoding.GetString(bBuffer);

            // If there is an attched ID3 v1.x TAG then read it 
            if (id3Tag.Substring(0, 3) == "TAG")
            {
                this.Title = id3Tag.Substring(3, 30).Trim();
                this.Artist = id3Tag.Substring(33, 30).Trim();
                this.Album = id3Tag.Substring(63, 30).Trim();
                this.Year = id3Tag.Substring(93, 4).Trim();
                this.Comment = id3Tag.Substring(97, 28).Trim();

                // Get the track number if TAG conforms to ID3 v1.1
                if (id3Tag[125] == 0)
                    this.Track = bBuffer[126];
                else
                    this.Track = 0;
                this.GenreID = bBuffer[127];

                this.hasTag = true;
                // ********* IF USED IN ANGER: ENSURE to test for non-numeric year
            }
            else
            {
                this.hasTag = false;
            }
        }

        public void updateMP3Tag()
        {
            // Trim any whitespace
            this.Title = this.Title.Trim();
            this.Artist = this.Artist.Trim();
            this.Album = this.Album.Trim();
            this.Year = this.Year.Trim();
            this.Comment = this.Comment.Trim();

            // Ensure all properties are correct size
            if (this.Title.Length > 30) this.Title = this.Title.Substring(0, 30);
            if (this.Artist.Length > 30) this.Artist = this.Artist.Substring(0, 30);
            if (this.Album.Length > 30) this.Album = this.Album.Substring(0, 30);
            if (this.Year.Length > 4) this.Year = this.Year.Substring(0, 4);
            if (this.Comment.Length > 28) this.Comment = this.Comment.Substring(0, 28);

            // Build a new ID3 Tag (128 Bytes)
            byte[] tagByteArray = new byte[128];
            for (int i = 0; i < tagByteArray.Length; i++) tagByteArray[i] = 0; // Initialise array to nulls

            // Convert the Byte Array to a String
            Encoding instEncoding = new ASCIIEncoding();   // NB: Encoding is an Abstract class // ************ To DO: Make a shared instance of ASCIIEncoding so we don't keep creating/destroying it
            // Copy "TAG" to Array
            byte[] workingByteArray = instEncoding.GetBytes("TAG");
            Array.Copy(workingByteArray, 0, tagByteArray, 0, workingByteArray.Length);
            // Copy Title to Array
            workingByteArray = instEncoding.GetBytes(this.Title);
            Array.Copy(workingByteArray, 0, tagByteArray, 3, workingByteArray.Length);
            // Copy Artist to Array
            workingByteArray = instEncoding.GetBytes(this.Artist);
            Array.Copy(workingByteArray, 0, tagByteArray, 33, workingByteArray.Length);
            // Copy Album to Array
            workingByteArray = instEncoding.GetBytes(this.Album);
            Array.Copy(workingByteArray, 0, tagByteArray, 63, workingByteArray.Length);
            // Copy Year to Array
            workingByteArray = instEncoding.GetBytes(this.Year);
            Array.Copy(workingByteArray, 0, tagByteArray, 93, workingByteArray.Length);
            // Copy Comment to Array
            workingByteArray = instEncoding.GetBytes(this.Comment);
            Array.Copy(workingByteArray, 0, tagByteArray, 97, workingByteArray.Length);
            // Copy Track and Genre to Array
            tagByteArray[126] = System.Convert.ToByte(this.Track);
            tagByteArray[127] = System.Convert.ToByte(this.GenreID);

            // SAVE TO DISK: Replace the final 128 Bytes with our new ID3 tag
            FileStream oFileStream = new FileStream(this.filename, FileMode.Open);
            if (this.hasTag)
                oFileStream.Seek(-128, SeekOrigin.End);
            else
                oFileStream.Seek(0, SeekOrigin.End);
            oFileStream.Write(tagByteArray, 0, 128);
            oFileStream.Close();
            this.hasTag = true;
        }
  

Now when i presss the show mp3 buttons(this populates the list box with the mp3's in the directory) it gives me an error saying the folded acsess is denied. Am i seeting it up wrong. i want the program to reaad the mp3 tags as it populates the listbox


here is the code that populates the list box. this is where i gert the error


 private void button2_Click(object sender, EventArgs e)
        {

            label2.Visible = true;
            string sourceDir = textBox1.Text + "\\iPod_Control\\Music";  \\This is whhere they would type the drive
            string targetDir = folderBrowserDialog1.SelectedPath;

            foreach (string d in Directory.GetDirectories(sourceDir))
            {

                foreach (string f in Directory.GetFiles(d, fileType))
                {
                    listBox1.Items.Add(Convert.ToString(f));//show whats going to be copied in the listbox before they rip it
               



                }

            }

Any Ideas
Firefox
Ewido
Tune up windows
Get detailed system information
My Fixes

Member - Alliance of Security Analysis Professionals - Since 2006
Reply With Quote  
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 5:21 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC