I have a folder with a number of .wav files inside. I need to dynamically count these files in order to generate the sound in a random way. I need this dynamically, so I don't need to update code everytime I update the sound folder with another sound.
I searched how to do it, but could only found examples for Windows. Here's the code I came up with:
string path = string.Format("/Sound/{0}", sourceSound);
return Directory.GetFiles(path, ".wav").Length;
I tried running it, but VS gives me the error:
"Unable to step. The code is currently unavailable."
Is there anything I'm doing wrong, or any other case how can we count the number of files inside a folder?
Thanks.
Try
using (var myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
var i = myIsolatedStorage.GetFileNames("*.wav").Length;
}
For some reason I couldn't make the example Vitalii gave me work. I was never able to get the count of files I have in the volder.
Looking over the internet, I stumbled upon this link:
confused about resources and GetManifestResourceNames()
The answer Zack gave on this thread, gave the insight I needed to make my App work.
I used Embedded Resource to find all the count of files I needed and, then, play the with a SoundEffectInstance.
The following link helped on this:
http://matthiasshapiro.com/2011/01/10/embedding-a-sound-file-in-windows-phone-7-app-silverlight/
Here's how I managed to make it work:
soundCount = GetSoundCount();
private int GetSoundCount()
{
return Assembly.GetExecutingAssembly().GetManifestResourceNames().Where(name => name.Contains(sourceImg)).Count();
}
With these few lines I managed to get the exact number of files I have in my App.
To make the sound play, I used the second link as an example and produced the code below:
if(soundInstance != null)
soundInstance.Stop();
this.soundInstance = SetNextSource();
soundInstance.Play();
private SoundEffectInstance SetNextSource()
{
Random random = new Random();
Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
Stream stream = assembly.GetManifestResourceStream(string.Format("Assembly Name.Folder.{0}.{1}.wav", SubFolder, FileName + random.Next(soundCount)));
SoundEffect se = SoundEffect.FromStream(stream);
return se.CreateInstance();
}
Well after a few days o research finally managed to make it work.
Hope this thread helps people facing the same problem I did.
Thanks.
Related
From research I have found that it is possible to determine the available space for storing app files on iOS, Android and UWP using dependency services with the Platform specific code below:
For iOS:
private double GetRemainingStorageSpace(string directoryPath)
{
var freeExternalStorage = NSFileManager.DefaultManager.GetFileSystemAttributes(directoryPath).FreeSize;
return (double)freeExternalStorage;
}
For Android it can be done like:
var path = new StatFs(directoryPath);
long blockSize = path.BlockSizeLong;
long avaliableBlocks = path.AvailableBlocksLong;
double freeSpace = blockSize * avaliableBlocks;
return freeSpace
or like this:
var fl = new Java.IO.File(directoryPath);
var freeSpace = fl.UsableSpace;
return (double)freeSpace;
For UWP:
string freeSpaceKey = "System.FreeSpace";
StorageFolder folder = await StorageFolder.GetFolderFromPathAsync(directoryPath);
var properties = await folder.Properties.RetrievePropertiesAsync(new string[]
{
freeSpaceKey
});
var freeSpace = properties[freeSpaceKey];
return (UInt64)freeSpace;
My question then is:
1.) Do these lines of code above actually return the amount of bytes that can be stored in a specific directory? Or do they return the amount of bytes that can be stored on the whole device?
2.) For Android I am not too sure what the difference between the two ways of doing this are I am hoping for an explanation of the difference between the both of then and which is a better to use?
Would appreciate an explanation.
1.) Do these lines of code above actually return the amount of bytes that can be stored in a specific directory? Or do they return the amount of bytes that can be stored on the whole device?
Obviously it is specific directory ,because in the code it needs specific folder path as parameter .
You can try to set directoryPath as
System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments)
and
System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal)
to see the difference.
2.) For Android I am not too sure what the difference between the two ways of doing this are I am hoping for an explanation of the difference between the both of then and which is a better to use?
I can't tell the difference or which is better, because based on my test the result comes the same , and for details you can refer to here , it's maybe helpful .
While doing automation I have to download files and store them in Cypress folder. File downloading and storing works, but I am not sure how to read those files since every time it is downloading its Prefix with some random number.
For Example
in the cypress/Animesh folder I can see some random files like 1234_abc.json, 2345_abc.json, 3334_abc.json, 3454_abc.json
How do I read the first file?
I am having a similar issue. I can successfully download the file but my issue is I cannot find a way to soft wait for it to be ready. I'm looking for something to check that there is at least one file in the folder. I'm using the findFile task but the issue is it doesn't wait, and i'm not sure how to get it to wait?
findFile: (mask) => {
if (!mask)
throw new Error('Missing a file mask to seach');
return globby(mask).then((list) => {
if (!list.length)
throw new Error(`Could not find files matching mask "${mask}"`);
return list[0];
});
}
});
The debugger seems to suppress viewing the contents of a UnicodeString in the Local Variable and Watch windows whenever the current function contains a UnicodeString::Length() call.
Running C++ Builder 10.3 Rio Enterprise (upgraded to 10.31 to try to solve the issue) where I have started a new project, added a button and put the following code in for the button. This a stripped down version of a large piece of code to track down and reproduce the issue.
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TFDQuery* qry = new TFDQuery(NULL);
UnicodeString search = "SELECT *\rFROM Client\rWHERE id>0;";
UnicodeString currLine;
int to, len;
qry->SQL->Clear();
to = search.Pos("\r");
while (to > 0) {
currLine = search.SubString(1, to-1);
qry->SQL->Add(currLine);
//len = search.Length()-1; // Offending line
search = search.SubString(to+1, 999999);
to = search.Pos("\r");
}
currLine = search;
qry->SQL->Add(currLine);
}
The picture below shows two different runs of this code. One is exactly as shown above (with one line commented out). The other shows with the line included.
My concern is that the the debugger only shows the apparent address of the variable named "search" and if I expand it, it shows "????", not the contents of the variable as shown by the arrow. Also note, the breakpoint is above the line that causes the debugger to switch views. Any ideas how I can get the contents of "search" to appear if I actually calculate the length of the substring (rather than placing "999999" for its length)?
After some experimenting, I can now partially answer my own question with a potential workaround. Replacing the "search.Length()" with "wcslen(search.c_str())" seems to work, at least it does not have the side effect of displaying only addresses for UnicodeStrings in the watch list and and local variables windows. At this point, I haven't thoroughly tested if this eventually raises some other problem. But why should I have to do this for such a fundamental type to the language?
I'm using Photoshop script. I get files from folders. My problem is that when I get the files and place them in an array the array contains hidden files that are in the folder for example ".DS_Store". I can get around this by using:
if (folders[i] != "~/Downloads/start/.DS_Store"){}
But I would like to use something better as I sometimes look in lots of folders and don't know the "~/Downloads/start/" part.
I tried to use indexOf but Photoshop script does not allow indexOf. Does anybody know of a way to check if ".DS_Store" is in the string "~/Downloads/start/.DS_Store" that works in Photoshop script?
I see this answer but I don't know how to use it to test: Photoshop script to ignore .ds_store
For anyone else looking for a solution to this problem, rather than explicitly trying to skip hidden files like .DS_Store, you can use the Folder Object's getFiles() method and pass an expression to build an array of file types you actually want to open. A simple way to use this method is as follows:
// this expression will match strings that end with .jpg, .tif, or .psd and ignore the case
var fileTypes = new RegExp(/\.(jpg|tif|psd)$/i);
// declare our path
var myFolder = new Folder("~/Downloads/start/");
// create array of files utilizing the expression to filter file types
var myFiles = myFolder.getFiles(fileTypes);
// loop through all the files in our array and do something
for (i = 0; i < myFiles.length; i++) {
var fileToOpen = myFiles[i];
open(fileToOpen);
// do stuff...
}
For anybody looking I used the Polyfill found here:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf
indexOf() was added to the ECMA-262 standard in the 5th edition; as
such it may not be present in all browsers. You can work around this
by utilizing the following code at the beginning of your scripts. This
will allow you to use indexOf() when there is still no native support.
This algorithm matches the one specified in ECMA-262, 5th edition,
assuming TypeError and Math.abs() have their original values.
I found LINQtoCRM (http://linqtocrm.codeplex.com/) and I started playing with it. It's nice, but before I get carried away I found there appears to be a showstopper: I can't figure out how to query against DynamicEntities (so I can query against my custom entities). Can someone confirm if this is currently impossible? Or give an example of how one would go about it?
This works:
var res = from c in p.Linq<task>()
select c;
string msg = "";
foreach (task dyn in res.ToList<task>())
{
msg += dyn.ToString();
}
If you s/task/DynamicEntity/ it no longer works :) Just want to confirm it's currently undoable before I go write lots more boilerplate...
edit: angle brackets
(I implemented the original version of LinqtoCRM and I'm still a maintainer).
I do not believe dynamic entities are supported. There is some related discussion on the forum. Maybe give XrmLinq a try.