Why does File.mkdirs() create two directories instead of one? - sd-card

This code should create a single directory:
File[] dirs = context.getExternalFilesDirs(type);
File dir = new File(dirs[dirs.length-1].getAbsolutePath());
dir.mkdirs();
return dir;
When I run it, it creates two directories:
mnt/sdcard/Android/data/com.test.sdcard
storage/0D68-5DA2/Android/data/com.test.sdcard
Why are both of these created?
It is important that I only have 1 directory.

Related

Flutter skip a directory from the copy file command

I'm copying files from one directory to another, but I want to exclude a directory, how can I proceed?
I tried to use the file_manager package as well but it doesn't work
var fm = FileManager(root: Directory('${externalDir.path}'));
var files = await fm.filesTree(
excludedPaths: ['/storage/emulated/0/Android/data/com.xxx.xxx/files/TEMP'],
extensions: ["mp3"],
);
in this way it should return me a list of mp3 files only, excluding the TEMP folder and its contents but this is not the case.

Batch Printing files to new folder as PDF's

I have a folder of 2000+ PDF files that I need to print and resave as new PDF files in a separate folder using the original file name. Is there a way to do this in powershell or using a CMD?
I have tried to select multiple files in the folder to print at the same time by right clicking and selecting the print option. However this gets stuck at the window requesting a new file name and a destination folder which I am unable to provide as each file needs to have the original file name.
// the directory to store the output.
string directory = Environment.GetFolderPath
(Environment.SpecialFolder.MyDocuments);
// initialize PrintDocument object
PrintDocument doc = new PrintDocument() {
PrinterSettings = new PrinterSettings() {
// set the printer to 'Microsoft Print to PDF'
PrinterName = "Microsoft Print to PDF",
// tell the object this document will print to file
PrintToFile = true,
// set the filename to whatever you like (full path)
PrintFileName = Path.Combine(directory, file + ".pdf"),
}
};
doc.Print();
I would like to see the new PDF file saved as a new PDF in the destination directory folder with the same file name as the origin directory.
Origin Directory and File name:
C:\Users\ts\P***S***\Legal\i3**\NonRedacted --> Origin File name "Random_Name.PDF"
Destination Directory and File name:
C:\Users\ts\P***S***\Legal\i3**\Redacted --> Destination File Name "Random_Name.PDF"

What does this setup.m file do and what is it for?

What does this setup.m file do?
function setup
%SETUP Adds directories for Metrics to your MATLAB path
%
% Author: Ben Hamner (ben#benhamner.com)
myDir = fileparts(mfilename('fullpath'));
paths = genpath(myDir);
paths = strread(paths,'%s','delimiter',':');
pathsToAdd = [];
for i=1:length(paths)
thisPath = paths{i};
thisPathSplit = strread(thisPath,'%s','delimiter','/');
addThisPath = 1;
% Do not add any directories or files starting with a . or a ~
for j=1:length(thisPathSplit)
thisStr = thisPathSplit{j};
if (~isempty(thisStr)) && ((thisStr(1) == '.') || (thisStr(1) == '~'))
addThisPath = 0;
end
end
if addThisPath ==1
if ~isempty(pathsToAdd)
thisPath = [':' thisPath];
end
pathsToAdd = [pathsToAdd thisPath];
end
end
addpath(pathsToAdd);
savepath;
I understand from the description that it adds directories to Matlab's search path. But which one and why? My Matlab scripts are often scattered with addpath('data') lines. Does this mean I don't have to do that anymore? Your comments are much appreciated.
The file that you are linking is a setup file for the Metrics package - it adds paths to various folders so that you can use Metrics package without setting up the paths manually.
More specifically the setup.m function adds all paths at the level and below where it is located. If you copy this file to any directory and run it - it will add this directory and all its subdirs and subdirs of subdirs etc. (excluding folders starting with . or ~)
But I have a hunch that what you are looking for is this:
http://www.mathworks.com/help/matlab/ref/startup.html
http://www.mathworks.com/help/matlab/ref/matlabrc.html
This is adding the directory that setup.m is located in as well as every sub directory within that directory. fileparts(mfilename('fullpath')) gets the directory that the file exists in, and genpath(myDir); gets all of the subdirectories. Note that this leaves out any directory starting with a '.' or a '~'

store the created file in a folder in every iteration,MATLAB

I m creating .wav file in every iteration of for loop and that .wav files are stored in the current directory where I am working on .Now I want to create a folder in current directory and each created file should get store in the created folder in each iteration...
for i=1:size(seg_data(:,1))
w(i,:)=data(seg_data(i,1): seg_data(i,2));
wavwrite(w(i,:),['file_',num2str(i)]);
end
You should use mkdir to create the new directory (once).
Then you should provide the relative path to the new folder to wavwrite
subFolderName = 'mySubFolder'; % for example
mkdir( subFolderName ); % if folder exists, a warning is issued
for ii=1:size( seg_data, 1 )
% ... do your stuff here
wavwrite( w(ii,:), fullfile( subFolderName, sprintf( 'file_%d', ii ) ) );
end
Note the use of fullfile to create path string - works for windows as well as linux paths.
PS,
It is best not to use i as a variable name in Matlab.

copy task in Cakefile

I am trying to copy all the files in a list of directories and paste them into an output directory. The problem is whenever I use an *, the output says there is no file or directory by that name exists. Here is the specific error output:
cp: cannot stat `tagbox/images/*': No such file or directory
cp: cannot stat `votebox/images/*': No such file or directory
If I just put the name of a specific file instead of *, it works.
here is my Cakefile:
fs = require 'fs'
util = require 'util'
{spawn} = require 'child_process'
outputImageFolder = 'static'
imageSrcFolders = [
'tagbox/images/*'
'votebox/images/*'
]
task 'cpimgs', 'Copy all images from the respective images folders in tagbox, votebox, and omnipost into static folder', ->
for imgSrcFolder in imageSrcFolders
cp = spawn 'cp', [imgSrcFolder, outputImageFolder]
cp.stderr.on 'data', (data) ->
process.stderr.write data.toString()
cp.stdout.on 'data', (data) ->
util.log data.toString()
You are using the * character, probably because that works for you in your shell. Using * and other wildcard characters that expand to match multiple paths is called "globbing" and while your shell does it automatically, most other programs including node/javascript/coffeescript will not do it by default. Also the cp binary itself doesn't do globbing, as you are discovering. The shell does the globbing and then passes a list of matching files/directories as arguments to cp. Look into the node module node-glob to do the globbing and give you back a list of matching files/directories, which you can then pass to cp as arguments if you like. Note that you could also use a filesystem module that would have this type of functionality built in. Note however that putting async code directly into a Cakefile can be problematic as documented here.