I know it's only cosmetic but the below code should rename my directory however it doesn't. The difference is just some capitalisation - but afaik Android is fully case sensitive when it comes to filenames. Like Linux normally is too.
The rename gives a true result, indicating the operation was successful. However the directory in question is NOT renamed, and it still has two capital D's.
I have previously used the same code to rename from /DeadDropDroid to /.DeadDropDroid and that works fine. Every time I run the below code the log says "success".
oldBasePath = new File (Environment.getExternalStorageDirectory()+ "/.DeadDropDroid/");
if (oldBasePath.exists()) {
if (oldBasePath.renameTo(new File(Environment.getExternalStorageDirectory()+ "/.DeaddropDroid/")))
Log.v(TAG, "Rename success.");
else
Log.v(TAG, "Rename fail.");
}
Have a look at this answer to a similar question. The key content is
By default, the SD card is formatted as FAT, which preserves case but is case insensitive.
I did some checks and can confirm that the mentioned File methods work 'case insensitive' on the SD card. You even can not check oldBasePath.exists() as ist also will return trueif the LowerCase directory version exists instead of the UpperCase version. You have to read the directory content and compare the file/directory names you received with your pattern.
Renaming will also be a two step approach (via a temp File), e.g
.DeadDropDroid -> .DeadDropDroid_tmp -> .DeaddropDroid
Related
Iam working on a quiz project in flutter. I stored my quiz text files in folders according to the quiz category. And all these folders are stored in one root folder. So I should be able to list all the folders in this root folder ( which are categories ). And when category folder is opened the files in that corresponding folder should be listed.
The goal is to make buttons with each folder's name and the button will hold the path to open that folder.
ie, if the user clicks a button for folder, a list will be made containing the names of folders inside the clicked folder and according to this list a listview of buttons will be made.and finally when you open folder containing quiz files same will happen but button will contain the corresponding file path.
I have made the folder tree and functions to make buttons according to the names stored in list. But I have no idea where to put this folder inside the project.
I have tried puttin in the root of project, in Lib folder, in asset folder but flutter is failing to detect this directory.
I really need this to work for my project to go forward. Any help of pointers will be appreciated.
For this to work you need multiple things:
Viewing you folders and text files within flutter
Listing your folders and text files
Reading your text files
1 - Viewing you folders and text files within flutter
Since the assets notations doesn't support recursion, you have to either:
Write everything by hand
Use a plugin to generate the assets for you
Since you have many file I suppose the second option is the best for you. I did struggle to find one that worked but FlutterAssetSync is working like a charm according to my tests. The only constrain is that you have to put everything inside the "assets" folder (which is not really a constraint tbh).
Once you put you file in the assets folder, execute the plugin (under Tools > FlutterAssetSync). This will automatically add everything to your pubspec.yaml
2 - Listing your folders and text files
In order to get the name of your folders and your text files you can use the answers to this stackoverflow question. Basically here is the implementation:
Future<List> _getImages(String folderName) async {
final manifestContent = await rootBundle.loadString('AssetManifest.json');
final Map<String, dynamic> manifestMap = json.decode(manifestContent);
return manifestMap.keys
.where((String key) => key.contains(folderPath))
.toList();
}
3 - Reading your text files
To read the content of a text file asset you must use loadString (as we did in _getImages btw). Here is a quick implementation:
Future<String> _getQuizzText(String quizzTextPath) async {
return await rootBundle.loadString(quizzTextPath);
}
Putting everything together you should be able to make it work!
I am creating a folder in android's internal storage by using the below code-
File file=new File(this.getFilesDir()+"/"+FolderNamefromEditTextasString);
file.mkdir();
I am getting the folder name from an Edit Text. I want to know how to check if the folder name is valid or not before creating. I don't exactly know which characters should not be there in a valid folder name. I first would like to validate the string from edit text. Also, I don't like to have spaces and "." in folder name string.
use regular expressions to test if it is something valid. I guess you can allow numbers, letters - and it can be ok not to allow special characters (such as ë,# and other)
something like [0-9a-zA-Z/-+]+ should work just fine
I am working inside a large legacy project that has a rich file structure. I know the name of the file I need to edit. But I don't remember where it is in the tree! In XCode I would use the filter in the project file view. But there doesn't seem to be something like that in Android Studio. What do I do?
You can simply press the Shift twice and enter the filename.
Shift + Ctrl + F or Shift + Cmd + F are usually used for searching for a specific word inside a scope be it the Directory, Module or the entire Project.
I thought of how to deal with this - using the Find in Path search (Shift+Ctrl+F or Shift+Cmd+F) search for "class ". Since file names correspond to class names in Java and Kotlin, you will get the file that contains the class definition in your list of results. If there are many classes that start with the same prefix, you can check the "Words" checkbox at the top of the Find in Path dialog.
As from the zip format specification http://en.wikipedia.org/wiki/Zip, it is possible to add two files with the same file name into a single zip archive file.
For example, I'd make a zip looks like
foo.zip
--bar.txt
--bar.txt
--3rd.txt
Does anyone know to accomplish this?
I tried linux utility zip and unzip, it always overwrites the previous added zip entry.
The Java class java.util.zip.ZipFile does not work either.
One way to do this is to create the zip initially using unique names - e.g. bar.txt, car.txt and 3rd.txt. Then open up the resulting zip file in a binary editor and search for car.txt and replace it with bar.txt.
Note that there should be two occurrences of the filename that you need to replace - one in the local file header for the file (somewhere in the middle of the zip), and one in the central directory (somewhere near the end of the zip).
If you need to do this programmatically, I would suggest you actually parse the central directory to find the exact positions of the filenames in the various headers rather than a simple search and replace to avoid the chance of false positive. It's not a very complicated format.
Note that when you try to uncompress a zip like this, you may get a warning about the file already existing when the second copy of the filename is uncompressed, depending on what program you are using for unzipping and what options you have set.
I am currently working on a project for android using Tesseract OCR. I was hoping to fine-tune the results given to the user by adding a dictionary. According to tesseract OCR wiki, the best way to go about this would be to
Replace tessdata/eng.user-words with your own word list, in the same
format - UTF8 text, one word per line.
However there is no eng.user-words file in the tessdata folder, I assume that if I just make a text file with my dictionary in it, it will never be used...
Has anybody had a similar experience and knows what to do?
If you're using tesseract 3 (which I assume you are).
You'll have to rebuild your eng.trainddata file.
I intended to replace the word-dawg file completely to try to get better results (ie - the words I'm detecting are always the same).
You'll need combine_tessdata and wordlist2dawg executables in the training directory when you compile tesseract.
unpack everything (i did this just to back up my eng.word-dawg, you'll also need the unicharset later)
./combine_tessdata -u eng.traineddata
create a textfile of your wordlist (wordlistfile)
create a eng.word-dawg
./wordlist2dawg wordlistfile eng.word-dawg traineddat_backup/.unicharset
replace the word-dawg file
./combine_tessdata -o eng.traineddata eng.word-dawg
that should be it.