Access Music File Metadata in Powershell [closed] - c#

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
So over the years between getting copied from one PC/hard drive to the next, my music collection is in a bit of a mess, so I want to go through each one programmatically and update the file metadata in the below screenshot (from right click > Properties on the file):
Some of the files are MP3 so I know ID3 can be used there (I had tried using Get-Content to view the last 128 bytes where the ID3 tags go, but only some small bits show as readable text, assuming this is because it's a binary file and needs decoded/parsed in some specific way). About an equal number are WMA (quite an old codec version, probably 7 or 8) and some are uncompressed WAV.
So I possibly need two things:
a) a way to access and update the ID3 info for the MP3 type files
b) a way to access the File Properties (at the Windows level) for WMA and WAV; if this method would also work for MP3 that'd be fantastic
Anyone got any ideas? I know this is possible in C# but that's a bit over my head right now as more used to scripting. If it needs to be done in a proper compiled program so be it but hoping there's a way to do it in shell.

Download the tagsharp.dll from HERE.
There is a separate module which can be used to modify any of the meta data like:
get-childitem mylocal.mp3 | set-album "MyLocalAlbum"
or something like this :
$files = Get-ChildItem D:\Folder -include *.mp3 -recurse
[System.Reflection.Assembly]::LoadFile("C:\TagLibDirectory\taglib-sharp.dll" )
foreach($iFile in $files)
{
$iFile.fullname
$mediaFile=[TagLib.File]::Create($iFile.fullname)
$mediaFile.Tag.Album = $iFile.Directory.Name
$mediaFile.Tag.AlbumArtists=$iFile.Directory.Name
$mediaFile.Save()
}
Hope it helps.

Related

Generate C code using C# [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I've got this task that requires me to generate some basic C code using a software written in C#.
The generated code should be based on some input files I provide to my software, we'll call it btOS for easy of communication.
So when starting btOS I give it as input file1, config.xml. When I hit run it should output a file.c that contains some basic structures and/or methods based on what the input files contain.
Is there any elegant way to do this ? Maybe some already generated templates or methods or stuff like that ? The only way I could think of handling this was creating specific strings in C# and outputting them to a C file.
L.E.: It seems that somehow my question was not clear enough. I assume the fault of including C++ in the title, I have remove it but I don't see how that is relevant because the question was very simple.
Anyway, to make it more clear. All i need to do is read some config files (their content is irrelevant, all they contain are some variables that will be used to generate some function templates, which will mostly impact the name of the function) - and write an output file with the extension .C (as in Main.c) that will contain those templates I generated.
So, again, the question: Are there any "elegant" and maybe somehow "professional" ways to do this other than using custom generated strings within the code that I will write to the file ? Right now the only way I see fit to do this without too much hassle is using some template text files with a naming convention defined by me(e.g. function_variableName{...}) where I just change the [variableName] text with whatever I need to to be there and "Abracadabra" I have a function that I will write to the file.
Now as Soonts suggested please try and be helpful, read multiple times if you don't clearly understand or maybe even don't bother - let somebody who is interested in this topic, tries to help or gain some new knowledge before flagging it.
Double Cheers.

How to give path properly in C# [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have a folder in my project named Export, I save files to that folder using this code :
document.Save(#"D:\workspace\folder1\Solution.Application.DataExporter\Export\mydocument.pdf");
But when others use this code, they complain that they don't have that path. How can I give path to my code so that it works everywhere? Thanks.
Option 1: Use the Environment.SpecialFolder to get the physical location of a special folder. See here for an overview of possible special folders.
For example, if you want to put the document in 'my documents' folder, then Environment.SpecialFolder.MyDocuments would give you the location to the my documents folder on the current machine.
Code:
var path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
This way you are sure you always have the correct and existing location. If needed, you can always first create an export folder into this special folder with Directory.CreateDirectory(), if it does not exist yet.
Option 2: Of course, you can always ask for a location to the user if you don't want to use a predefined one, by using the SaveFileDialog class, for example.
Create the folder 'Export' in MyDocuments, and then save the file to that directory. As many others have pointed out. You need to save to a directory, that the executing user has access rights to.
string documentFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), #"Export");
if (!Directory.Exists(documentFolder))
{
Directory.CreateDirectory(documentFolder);
}
document.Save(Path.Combine(documentFolder, "mydocument.pdf"));

How do I write search algorithm in c sharp? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I am writing simple program that will assist me to configure and sort out my files.I want the algorithm to search for matching string or text that the user inputs in the search box like windows search index , Google,or any other search engines.I doesn't have to be complex,just simple.you can show me by example or direct me to the appropriate resource.
https://support.microsoft.com/sv-se/kb/303974
Has some information that will get you going.
Edit: string[] files = Directory.GetFiles("C:\\", "*.dll");
This line will search through all files in c:\ for a file thats ending with .dll
Now you want it to search through all files that starts with something then youd have to run "yourstring*". In your example case, you only remember the starting "tes". Directory.GetFiles("C:\\", "tes*"); This line will search for a file starting with the filename "tes"
You can also use Directory.GetDirectories("C:\\"); to get all directories in c:\ and if you want then, loop through those directories with the same method to find all the subdirectories, then search for your file in all of those directories.

How I can read after EOF? C# [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I`m using C# and I need to read something after EOF. Is it possible by using C#? How?
Thanks.
You cant. EOF means end of file, there's nothing actually in the file after that.
You may as well ask how you can get ten gallons of oil from a four-gallon drum. Once it's empty, there's no more to be had.
Since you're talking C# hence Windows (and based on your comment and data located behind the end of file pointer), it's possible that they may be referring to "DOS mode" text files, which are (or used to be, I haven't investigated recently) terminated by the CTRL-Z character.
From the earliest days of the PC revolution, where CP/M used integral numbers of disk blocks to store a file and only stored the number of disk blocks rather than the number of bytes, CTRL-Z was used to indicate end of file if the file wasn't an exact multiple of the disk block size.
If that's the case, it's probably best just to open the file as a binary file, then read up to the first CTRL-Z character (code point 26) - everything beyond that could be considered data beyond EOF if it's truly a text file of that format.

File Paths Are Too Long - Crashing FTP Transfers [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I am using licensed version of CuteFTP to transfer files(Thousands in number) for one server to another.
The problem I am facing now is most of the FTP transfers are failing as File Paths Are Too Long.
On average, the character length of my file path would be anywhere between 200 & 250.
I cannot individually shorten the file titles manually as there are huge number of files.
Any ideas or suggestions to overcome this problem?
This is an limitation of Windows more specifially the NTFS File system. The MAX_PATH define does allow you to create files with a total (path and file name) length of 260 characters. The easy way is to use Robocopy which can deal with such file names or if you are bound to FTP you will get an error when the target file name is too long. The only easy way out of this is to create a zip file the the files in question and transfer the zip file. This should be a good idea anyway since the transfer over the wire is much slower than to simply stream one big file which is 2-4 times smaller than the original data.
As bonus you get rid of the long file names until you try to unpack them. But then you should choose your folder structure in a way to have a shallow root directory.

Categories