Tuesday, June 3, 2008

Formatting my MP3 player

My current MP3 player is a SanDisk Sansa c250. It’s not a fancy as some of the more expensive units, but overall it’s very nice unit for the price. Recently I needed to transfer 1GB of data between to pc’s and didn’t have a flash drive handy; so I just copied the data to my Sansa and used it for the transfer. This seemed like a good idea at the time, but when I tried to delete the data from the MP3 player, I was faced the the error message “Folder cannot be deleted because it is protected.”. After some experimenting, it looks like the Sansa will not let you delete a folder if it contains data. This wouldn’t be a big deal, except that the data I had transferred contained hundreds of folders. There was no way I was going to dig through all of these folders to delete the files. Being a developer, I decided to automate the process and write a .NET application that would traverse the folder structure of the unit, and delete all of the files.

I threw together a quick app, tested it on some other folders, and was off to the races (or so I thought). I attempted to select the folder on the device (using the .NET FolderBrowserDialog), and Windows Vista gave me the error message “The folder cannot be used”.

I had never tried to access a portable device programmatically, so I wasn’t sure what the cause might be. Google’ing didn’t help. Next, I did some debugging to find out what the referenced file path was so I could just hard code it. The path turned out to be in Temporary Internet Files. I’m not quite sure what this means, but obviously Windows doesn’t treat this device like a normal drive.

It was time to take a step back and think about what I was trying to accomplish. I wanted everything deleted from the device, except for my music. But, all my MP3’s are backed up on several devices. I took a quick look at the options on the Sansa, and it turns on there was a format device. This quickly wiped out everything, and then I simply copied the music back to the device.

I guess sometimes, it pays to approach a problem from a different perspective.

No comments: