0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Zipファイルから中身を取り出すC#プログラム(=pptxファイルからm4aを取り出す)

Posted at

パワポに埋め込まれた音声ファイル(.m4a)を別ファイルに保存する
「メディアに名前を付けて保存」という機能が、パワポマクロには無いという。

ChatAIに聞いたら、pptxはzipファイルだから、zipファイルの中を探索して、中の音声ファイルを取り出して保存すればいい、という。
うそーん、と思ったけど、そのプログラム。

OutComp.cs
//c:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe /target:exe /reference:System.IO.Compression.dll;System.IO.Compression.FileSystem.dll;System.IO.Compression.ZipFile.dll; OutComp.cs

//C:\Windows\Microsoft.NET\Framework\v4.0.30319
//System.IO.Compression.dll
//System.IO.Compression.FileSystem.dll
//System.IO.Compression.ZipFile.dll

using System;
using System.IO;
using System.IO.Compression;
class OutComp
{
	static void Main()
	{
		// zipファイルのパス
		string zipPath = @"C:\hogehoge\p1.pptx";
		string extractPath = @"C:\hogehoge\out\";
		using (ZipArchive archive = ZipFile.OpenRead(zipPath))
		{
			foreach (ZipArchiveEntry entry in archive.Entries)
			{
				if (Path.GetExtension(entry.FullName).Equals(".m4a", StringComparison.OrdinalIgnoreCase))
				{
					string destinationPath = Path.Combine(extractPath, entry.Name);
					entry.ExtractToFile(destinationPath, true);
				}
			}
		}
	}
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?