2017년 8월 22일 화요일

file component needs ability to create new directory


The file component is very useful.  The only problem is it can not save to custom directories, or create new directories.
If to apps created with ai are creating files with the same filename the file will be overwritten by the app most recently accessing it.
File directories should at least be separated by package name if the ability to create directories can not implemented.

--
App Inventor is an Open Source project.  Feel free to dabble wit the source code yourself!

The source code is located here:  http://appinventor.mit.edu/appinventor-sources/

--
the file component actually can create a directory, see below

File.SaveFile "/Taifun/dummy.txt"
                      "Woo Hoo"

File.Delete "/Taifun/dummy.txt"

this creates a directory Taifun in the root directory of your device
after deleting the dummy file, the directory should be empty

EDIT: sorry, this statement was wrong, see also here File.SaveFile method currently can't create a folder

--
Can I use wildcards to delete as well.  This is just a work around to the real problem though.  It is saving resource files in a common folder to all app inventor apps

--
no, you can't use wildcards
but if you like to explain your real problem, probably we can help...

--
I know that is not cool resurrect old post but I consider that my point maybe is ok in this thread.
Using the filecomponent save file with a structure or path like: /xxxx/xxx.txt does not work for me. I do not why. But I find a way to create any folder in the SDCARD.
I attack the image here.
With this method I can put files, like csv, txt or jpg in folders, create many folders and put images in the folders (this last using a hide canvas and put a standard height and width, I am looking how to improve that)

Two very important thinks to consider:
1. To share files it is necessary put /sdcard/ in the path for example:  
If you create a file like: /Folder/filename.csv you must share it with the follo path: /sdcard/Folder/filename.csv
2. To delete files from SDCARD you must ignore the /sdcard/ on the path and you can use the File.Delete block with the path: /Folder/filename.csv

Due it is imposible get the names of files in a folder, I use a tinyDB and save each image and use it for delete each image one by one. Still I cannot find a method to delete folder :(

See you and hope that this information works for all people that want to do that without third party apps.

--
@ Carlium     Thank you very much for your tip about a different way to use the File component.     I re-posted your small tutorial here to make it available to more users and easier to search  Tip: Working with the File component .. a new way

(It is OK to comment on 'old' posts if they are still open.   It is often better to start a new post).

Thank you very much for sharing with the AI2 Community.

--
thank you Carlium, this is the workaround we have to use currently
my statement was wrong, see also here File.SaveFile method currently can't create a folder

--

댓글 없음:

댓글 쓰기