Free space on removable cards

Caravelle

Active Member
Licensed User
Longtime User
I am converting a program I wrote with B4PPC to transfer files in large numbers from one card to another using the device (Asus TF101, Android 3.1) to run the process. The main use is to move photo files from a full camera CF card (in a USB adapter) to a 32 gig SD card, either for backup purposes or to free the CF card for further use. There can be well over 1,000 3MB+ files on a 4 gig CF card, so all sorts of questions arise and I don't know the answers yet - expect more from me in the future !

My current question is how do I tell if there is enough space on the receiving removable card for the files I want to transfer to it ? Even an external app like "File Manager HD", which analyses storage used, won't drill down beyond the main (non-removable) SDcard directory to the removable directory. As tablets with comprehensive external storage become more popular, surely this must become a necessary function?

My first thought is to add up the filesizes of all files on the receiving card and subtract that from the basic known size of the card. Then add up the filesizes of the files to be transferred, and see which is bigger. With 1000+ files to be transferred and potentially 10,000 on the receiving card this might take some time... (I take a lot of photos when I go away, indeed that is the whole point of going away at great expense so I make the most of it). I believe I can short-circuit the process somewhat.

Each of my cards has a tiny file "ID.txt" which contains an identifying name for the card, for example my single 32 gig MicroSD card is "MSD32-1", the 4 gig CF cards are "CF4-1", "CF4-2" and so on. If the MicroSD card gets full, there is a 32 gig SD Card ("SD32-1") to carry on the task. I could add a line of text in this file on the receiving cards which shows the space available as shown on my desktop PC before I go away, then check the ID file that there is enough space before each image file is added, and re-write it afterwards with a number representing the previous figure less the size of the new file - ie space remaining.

In any case, I suspect there may be an issue with files taking up more physical room than their actual size in bytes so more research will be needed.

This seems like an awful lot of trouble to go to for what should be a simple task, so have I missed something hidden away in a library or does anyone have any suggestions ? I'm a newbie with B4A so please don't make it complicated.

Thanks

Caravelle
 

Caravelle

Active Member
Licensed User
Longtime User
Do these work with removable drives, and if so how? It seems to me that they're intended for internal memory and the "external" SD card which isn't removable.

The first solution is any any case way beyond me -
I'm a newbie with B4A so please don't make it complicated.

Thanks

Caravelle
 
Upvote 0

Caravelle

Active Member
Licensed User
Longtime User
It's a problem that needs solving - if that's at all possible - with a function along the lines of FreeSpace(PathToRemovableDrive) since that path will vary from device to device - and mine has four of them !

In B4PPC the DriveInfo library had it covered, I could plug CF and SD cards and USB devices into my device, and read off their freespace with no problem at all.

Cheers

Caravelle
 
Upvote 0

Caravelle

Active Member
Licensed User
Longtime User
Did I mention I was a newbie at this ?

I tried the program and got nowhere, this was not the one to refer me to as it introduces considerable complication but very little explanation of what's going on. What made more sense was the example for "Shell" in the phone library documentation.

B4X:
Dim p As Phone
Dim sb As StringBuilder
sb.Initialize
p.Shell("df", Null, sb, Null)
Msgbox(sb.ToString, "Free space:")

Those with removable devices will be pleased to know that this example will list out size, used, free and Blocksize for each removable device, at the end of the StringBuilder "sb" which is retrieved. See the attached screenshot. :sign0060: I can only vouch for the Asus Transformer but it looks good for other devices that boast comprehensive storage facilities.

All I have to do now is master the art of extracting the bits I want from it for use in my program. String-processing I can do... I might also try to write a sub where you feed a card name in and get the relevant stats out, but that's not strictly necessary yet.

One more question, and if it's appropriate I'll try again in another thread. Is it possible to in some way catch card insertion and extraction events, so that I can change cards and have the usage data automatically updated ? The device is obviously aware of these as it shows icons on the bar at the bottom of the screen when a card is inserted, and they vanish when the card is removed. There's a full set in my screenshot.

Thanks

Caravelle
 

Attachments

  • TF101_Freespace.jpg
    TF101_Freespace.jpg
    80.5 KB · Views: 334
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
One more question, and if it's appropriate I'll try again in another thread. Is it possible to in some way catch card insertion and extraction events, so that I can change cards and have the usage data automatically updated ? The device is obviously aware of these as it shows icons on the bar at the bottom of the screen when a card is inserted, and they vanish when the card is removed. There's a full set in my screenshot.
It is possible to catch this event. However a simpler approach is to check for mounted media in Activity_Resume. This way when your program becomes visible it will show the correct list of cards.
 
Upvote 0

Caravelle

Active Member
Licensed User
Longtime User
Thank you, Erel, but what I have in mind is something to detect insertion or removal while the program is still active. I may want to transfer more than one card of photos, or if the receiving card becomes full I may want to change it for another. I was hoping I could trigger a "refresh data" sub automatically, instead of manually with a button.

Caravelle
 
Upvote 0
Top