/// <summary> /// 切割mp3 /// </summary> /// <param name="mp3"></param> /// <param name="mp3FilePath"></param> /// <param name="savePath"></param> public void SplitMP3(MP3Info mp3, string mp3FilePath, string savePath) { Process ffmpegProcess = new Process(); ffmpegProcess.StartInfo.UseShellExecute = false; ffmpegProcess.StartInfo.ErrorDialog = true; ffmpegProcess.StartInfo.CreateNoWindow = true; ffmpegProcess.StartInfo.FileName = AppDomain.CurrentDomain.BaseDirectory + "/ffmpeg/ffmpeg.exe"; string beginTime = ToHourTime(mp3.StartTime).ToString("HH:mm:ss.fff"); string endTime; if (string.IsNullOrEmpty(mp3.NextPosTime)) { Shell32.ShellClass sc = new Shell32.ShellClass(); var fd = sc.NameSpace(Path.GetDirectoryName(mp3FilePath)); var item = fd.ParseName(Path.GetFileName(mp3FilePath)); mp3.NextPosTime = fd.GetDetailsOf(item, 27).Substring(3) + ".00"; } endTime = GetSplitTime(ToHourTime(mp3.NextPosTime).AddSeconds(-0.2) - ToHourTime(mp3.StartTime));//尾部去除部分衔接静音(这里是0.2秒) ffmpegProcess.StartInfo.Arguments = "-y -i " + mp3FilePath + " -ss " + mp3.StartTime + " -t " + endTime + " -acodec copy " + savePath + "/" + mp3.Name + ".mp3"; ffmpegProcess.Start(); ffmpegProcess.WaitForExit(); }
public List <LinkType> LoadLinksFromStartup() { DirectoryInfo di = new DirectoryInfo(GetStartupPath()); FileInfo[] files = di.GetFiles("*DelayStartup.lnk"); List <LinkType> listOfLinks = new List <LinkType>(); foreach (FileInfo fi in files) { //parse link into string string pathOnly = Path.GetDirectoryName(fi.FullName); string filenameOnly = Path.GetFileName(fi.FullName); Shell32.Shell shell = new Shell32.ShellClass(); Shell32.Folder folder = shell.NameSpace(pathOnly); Shell32.FolderItem folderItem = folder.ParseName(filenameOnly); if (folderItem != null) { Shell32.ShellLinkObject link = (Shell32.ShellLinkObject)folderItem.GetLink; LinkType a = new LinkType(link, fi); listOfLinks.Add(a); } } return(listOfLinks); }
public static void PinUnpinTaskBar(string filePath, bool pin) { if (!string.IsNullOrEmpty(filePath) && File.Exists(filePath)) { string directory = Path.GetDirectoryName(filePath); string filename = Path.GetFileName(filePath); Shell shell = new ShellClass(); Folder folder = shell.NameSpace(directory); FolderItem folderItem = folder.ParseName(filename); FolderItemVerbs verbs = folderItem.Verbs(); for (int i = 0; i < verbs.Count; i++) { FolderItemVerb verb = verbs.Item(i); string verbName = verb.Name.Replace(@"&", string.Empty); if ((pin && verbName.Equals("pin to taskbar", StringComparison.InvariantCultureIgnoreCase)) || (!pin && verbName.Equals("unpin from taskbar", StringComparison.InvariantCultureIgnoreCase))) { verb.DoIt(); return; } } } }
public static void Unzip(string zipfile, string targetPath, Func<FolderItem, bool> preUnzipCallback = null, Action<string> postUnzipCallback = null) { ShellClass sc = new Shell32.ShellClass(); Folder SrcFolder = sc.NameSpace(zipfile); Folder DestFolder = sc.NameSpace(targetPath); FolderItems items = SrcFolder.Items(); for (int i = 0; i < items.Count; i++) { FolderItem item = items.Item(i); if (preUnzipCallback == null || preUnzipCallback(item)) { DestFolder.CopyHere(item, 20); if (postUnzipCallback != null) { if (!targetPath.EndsWith("\\")) { targetPath += '\\'; } string targetFile = targetPath + item.Name; if (File.Exists(targetFile)) { postUnzipCallback(targetFile); } else { ExceptionHandler.Raise("Cannot find the unziped file.\r\n{0}", targetFile); } } } } }
protected void browse_folder_Click(object sender, EventArgs e) { Shell32.ShellClass shl = new Shell32.ShellClass(); Shell32.Folder2 fld = (Shell32.Folder2)shl.BrowseForFolder(0, "Select a directory", 0, System.Reflection.Missing.Value); if (fld != null) { text_path.Text = fld.Self.Path; } }
public static MP3File ReadID3Tags(string FileFullPath) { MP3File mp3File = new MP3File(); //parse file name string fileName = FileFullPath.Substring(FileFullPath.LastIndexOf("\\") + 1); //parse file path string filePath = FileFullPath.Substring(0, FileFullPath.LastIndexOf("\\")); //create shell instance Shell32.Shell shell = new Shell32.ShellClass(); //set the namespace to file path Shell32.Folder folder = shell.NameSpace(filePath); //get ahandle to the file Shell32.FolderItem folderItem = folder.ParseName(fileName); //did we get a handle ? if (folderItem != null) { mp3File.FileName = fileName.Trim(); //query information from shell regarding file mp3File.ArtistName = folder.GetDetailsOf(folderItem, 16).Trim(); mp3File.AlbumName = folder.GetDetailsOf(folderItem, 17).Trim(); mp3File.SongTitle = folder.GetDetailsOf(folderItem, 10).Trim(); mp3File.Genre = folder.GetDetailsOf(folderItem, 20).Trim(); mp3File.Time = folder.GetDetailsOf(folderItem, 21).Trim(); mp3File.Duration = folder.GetDetailsOf(folderItem, 27).Trim(); string[] tags = new string[25]; for (int i = 0; i < 25; i++) { try { tags[i] = folder.GetDetailsOf(folderItem, i); } catch { } } mp3File.FileFullPath = FileFullPath.Trim(); try { mp3File.TrackNumber = Int32.Parse(folder.GetDetailsOf(folderItem, 19)); } catch { } } //clean ip folderItem = null; folder = null; shell = null; //return mp3File instance return(mp3File); }
public static TimeSpan GetInfo(string audioPath) { var dirName = Path.GetDirectoryName(audioPath); var SongName = Path.GetFileName(audioPath);//获得歌曲名称 FileInfo fInfo = new FileInfo(audioPath); Shell32.ShellClass sh = new Shell32.ShellClass(); Folder dir = sh.NameSpace(dirName); FolderItem item = dir.ParseName(SongName); var timeString = Regex.Match(dir.GetDetailsOf(item, -1), "\\d:\\d{2}:\\d{2}").Value;//获取歌曲时间 return(TimeSpan.Parse(timeString)); }
/// <summary> /// 获取媒体文件播放时长/// /// </summary> /// <param name="path">媒体文件路径</param> /// <returns></returns> public TimeSpan GetMediaTimeLen(string path) { Shell32.Shell shell = new Shell32.ShellClass( ); //文件路径 Shell32.Folder folder = shell.NameSpace(path.Substring(0, path.LastIndexOf("\\"))); //文件名称 Shell32.FolderItem folderitem = folder.ParseName(path.Substring(path.LastIndexOf("\\") + 1)); string _duration = Regex.Match(folder.GetDetailsOf(folderitem, -1), "\\d:\\d{2}:\\d{2}").Value; string[] sp = _duration.Split(new char[] { ':' }); TimeSpan ts = new TimeSpan(int.Parse(sp[0]), int.Parse(sp[1]), int.Parse(sp[2])); return(ts); }
private static string GetShortcutTargetFile(string shortcutFilename) { string pathOnly = Path.GetDirectoryName(shortcutFilename); string filenameOnly = Path.GetFileName(shortcutFilename); Shell32.Shell shell = new Shell32.ShellClass(); Shell32.Folder folder = shell.NameSpace(pathOnly); Shell32.FolderItem folderItem = folder.ParseName(filenameOnly); if (folderItem != null) { Shell32.ShellLinkObject link = (Shell32.ShellLinkObject)folderItem.GetLink; return(link.Path); } return(String.Empty); }
/// <summary> /// 功能:解压zip格式的文件。 /// </summary> /// <param name="zipFilePath">压缩文件路径</param> /// <param name="unZipDir">解压文件存放路径,为空时默认与压缩文件同一级目录下,跟压缩文件同名的文件夹</param> /// <param name="err">出错信息</param> /// <returns>解压是否成功</returns> public static bool UnZipFile(string zipFilePath, string unZipDir, out string err) { err = ""; if (zipFilePath.Length == 0) { err = "压缩文件不能为空!"; return(false); } else if (!zipFilePath.EndsWith(".zip")) { err = "文件格式不正确!"; return(false); } else if (!System.IO.File.Exists(zipFilePath)) { err = "压缩文件不存在!"; return(false); } //解压文件夹为空时默认与压缩文件同一级目录下,跟压缩文件同名的文件夹 if (unZipDir.Length == 0) { unZipDir = zipFilePath.Replace(System.IO.Path.GetFileName(zipFilePath), System.IO.Path.GetFileNameWithoutExtension(zipFilePath)); } if (!unZipDir.EndsWith("\\")) { unZipDir += "\\"; } if (!System.IO.Directory.Exists(unZipDir)) { System.IO.Directory.CreateDirectory(unZipDir); } try { Shell32.ShellClass sc = new Shell32.ShellClass(); Shell32.Folder SrcFolder = sc.NameSpace(zipFilePath); Shell32.Folder DestFolder = sc.NameSpace(unZipDir); Shell32.FolderItems items = SrcFolder.Items(); DestFolder.CopyHere(items, 20); } catch (Exception ex) { err = ex.Message; return(false); } return(true); }//解压结束
public string GetShortcutTargetFile(string shortcutFilename) { string pathOnly = System.IO.Path.GetDirectoryName(shortcutFilename); string filenameOnly = System.IO.Path.GetFileName(shortcutFilename); Shell32.Shell shell = new Shell32.ShellClass(); Shell32.Folder folder = shell.NameSpace(pathOnly); Shell32.FolderItem folderItem = folder.ParseName(filenameOnly); if (folderItem != null) { Shell32.ShellLinkObject link = (Shell32.ShellLinkObject)folderItem.GetLink; return link.Path; } return String.Empty; // Not found }
public static string GetShortcutTargetFile(string shortcutFilename) { string directory = Path.GetDirectoryName(shortcutFilename); string filename = Path.GetFileName(shortcutFilename); S32.Shell shell = new S32.ShellClass(); S32.Folder folder = shell.NameSpace(directory); S32.FolderItem item = folder.ParseName(filename); if (item == null) { return(String.Empty); } S32.ShellLinkObject link = (S32.ShellLinkObject)item.GetLink; return(link.Path); }
public WmaMessage(string path) { //create shell instance Shell32.Shell shell = new Shell32.ShellClass(); //set the namespace to file path Shell32.Folder folder = shell.NameSpace(path.Substring(0, path.LastIndexOf("\\"))); //get ahandle to the file Shell32.FolderItem folderItem = folder.ParseName(path.Substring(path.LastIndexOf("\\") + 1)); //did we get a handle ? title = folder.GetDetailsOf(folderItem, 9); artist = folder.GetDetailsOf(folderItem, 16); album = folder.GetDetailsOf(folderItem, 10); pubyear = folder.GetDetailsOf(folderItem, 18); genre = folder.GetDetailsOf(folderItem, 12); size = folder.GetDetailsOf(folderItem, 1); type = folder.GetDetailsOf(folderItem, 2); bps = folder.GetDetailsOf(folderItem, 22); track = folder.GetDetailsOf(folderItem, 34); }
///// <summary> ///// 文件地址 ///// </summary> //public string Url //{ // get { return url; } //} public Mp3Message(string FilePath) { //url = GetRootURI()+FilePath.Remove(0,FilePath.IndexOf("\\upload\\")).Replace("\\","/"); Shell32.Shell shell = new Shell32.ShellClass(); //set the namespace to file path Shell32.Folder folder = shell.NameSpace(FilePath.Substring(0, FilePath.LastIndexOf("\\"))); //get ahandle to the file Shell32.FolderItem folderItem = folder.ParseName(FilePath.Substring(FilePath.LastIndexOf("\\") + 1)); //did we get a handle ? title = folder.GetDetailsOf(folderItem, 9); artist = folder.GetDetailsOf(folderItem, 16); album = folder.GetDetailsOf(folderItem, 10); pubyear = folder.GetDetailsOf(folderItem, 18); genre = folder.GetDetailsOf(folderItem, 12); size = folder.GetDetailsOf(folderItem, 1); type = folder.GetDetailsOf(folderItem, 2); bps = folder.GetDetailsOf(folderItem, 22); track = folder.GetDetailsOf(folderItem, 34); }
private void browseButton_Click(object sender, EventArgs e) { ShellClass shell; Folder2 folder; // Call the shell folder browsing dialog shell = new Shell32.ShellClass(); folder = (Folder2)shell.BrowseForFolder( 0, "Browse for Infantry Folder", 0, null ); if (folder != null) { browseTextBox.Text = folder.Self.Path; OptionsModified(); } }
/// <summary> /// 构造函数 /// </summary> /// <param name="FilePath">文件路径</param> public ID3V2Tag(string FilePath) { ID3Info info = new ID3Info(FilePath, true); foreach (AttachedPictureFrame AP in info.ID3v2Info.AttachedPictureFrames.Items) { TrackImages.Add(Image.FromStream(AP.Data)); } ////曲名 TrackTitleName = info.ID3v2Info.GetTextFrame("TIT2"); ////艺术家 ArtistName = info.ID3v2Info.GetTextFrame("TPE1"); ////专辑 AlbumName = info.ID3v2Info.GetTextFrame("TALB"); ////音轨 TrackNo = info.ID3v2Info.GetTextFrame("TRCK").Trim(); ////碟号 DiscNo = info.ID3v2Info.GetTextFrame("TPOS").Trim(); ////年份 SalesYear = info.ID3v2Info.GetTextFrame("TYER").Trim(); if (TrackNo == string.Empty) TrackNo = "1"; if (DiscNo == string.Empty) DiscNo = "1"; string SongName = Path.GetFileName(FilePath);//获得歌曲名称 FileInfo fInfo = new FileInfo(FilePath); Shell sh = new ShellClass(); Folder dir = sh.NameSpace(FilePath.Substring(0, FilePath.LastIndexOf(@"\"))); FolderItem item = dir.ParseName(SongName); try { MainFormat format = new MainFormat(); this.TrackLength = dir.GetDetailsOf(item, 27); this.BitRate = dir.GetDetailsOf(item, 28); } catch { } }
/// <summary> /// Shell32 for x86 using to show file details and base on Framework2.0 ,distinct to the project ExcelAddIn4(using Framework 3.5) /// </summary> /// <param name="fullname"></param> /// <param name="filename"></param> /// <returns></returns> public string getFileDetail(string fullname, string filename) { string returnValue = string.Empty; //The file path to get a property string filePath = fullname + "\\" + filename; //Initialize the Shell interface Shell32.Shell shell = new Shell32.ShellClass(); //Gets the file where the parent directory objects Folder folder = shell.NameSpace(filePath.Substring(0, filePath.LastIndexOf("\\"))); //Gets the file corresponding to the FolderItem object FolderItem item = folder.ParseName(filePath.Substring(filePath.LastIndexOf("\\") + 1)); //Key relation dictionary stored attribute names and values //Dictionary<string, string> Properties = new Dictionary<string, string>(); int i = 0; while (true) { //Gets the attribute name string key = folder.GetDetailsOf(null, i); if (string.IsNullOrEmpty(key)) { //When no properties desirable, EXIT cycle break; } //Getting the property value string value = folder.GetDetailsOf(item, i); if (key == "Comments") { returnValue = value; break; } //Save attribute //Properties.Add(key, value); i++; } return(returnValue); }
public ActionResult GetMvcActionResult(String resourceUrl, String dataType) { //var uri = "http://zhangmenshiting.baidu.com/data2/music/31400032/3138763390000.mp3?xcode=43291b682c5378e18cc76ec8e46cb803"; WebClient client = new WebClient(); client.Encoding = System.Text.Encoding.UTF8; if (dataType == "string") { var result = client.DownloadString(resourceUrl); return Json(result); } else if (dataType == "file") { var path = string.Format("E://temp/{0}.mp3", Guid.NewGuid().ToString()); client.DownloadFile(resourceUrl, path); var fileInfo = new FileInfo(path); ShellClass shClass = new ShellClass(); Folder dir = shClass.NameSpace(Path.GetDirectoryName(path)); FolderItem item = dir.ParseName(Path.GetFileName(path)); var title = dir.GetDetailsOf(item, 10); fileInfo.MoveTo(path.Replace(Path.GetFileNameWithoutExtension(path), title)); return Json("下载完成"); } return Json("类型不匹配"); }
/// <summary> /// Gets the shortcut link behind the given path /// Credits of http://www.saunalahti.fi/janij/blog/2006-12.html /// </summary> /// <param name="shortcutPath">The path of the shortcut to check up on</param> /// <returns>The link of the shortcut</returns> public static string GetShortcutTargetFile(string shortcutPath) { string extension = Path.GetExtension(shortcutPath); // Check if the file extension is that of a shortcut file if (extension.ToLower() == ".lnk") { string pathOnly = Path.GetDirectoryName(shortcutPath); string filenameOnly = Path.GetFileName(shortcutPath); Shell shell = new ShellClass(); Folder folder = shell.NameSpace(pathOnly); FolderItem folderItem = folder.ParseName(filenameOnly); if (folderItem != null) { ShellLinkObject link = (ShellLinkObject) folderItem.GetLink; return link.Path; } } return null; // not found }
private void selectLogFolder() { string strPath = ""; string strCaption = "Select a directory"; DialogResult result; ShellClass shell = new ShellClass(); Folder2 folder = (Folder2)shell.BrowseForFolder(0, strCaption, 0, System.Reflection.Missing.Value); if (folder == null) { result = DialogResult.Cancel; } else { strPath = folder.Self.Path; result = DialogResult.OK; } if (result == DialogResult.OK) { textBoxLogFilePath.Text = strPath; } }
private static string GetShortcutTargetPath(string shortcutPath) { string directory = Path.GetDirectoryName(shortcutPath); string filename = Path.GetFileName(shortcutPath); try { Shell shell = new ShellClass(); Folder folder = shell.NameSpace(directory); FolderItem folderItem = folder.ParseName(filename); if (folderItem != null) { ShellLinkObject link = (ShellLinkObject)folderItem.GetLink; return link.Path; } } catch (Exception e) { DebugHelper.WriteException(e); } return null; }
public void Test() { ShellClass cl = new ShellClass(); }
private static void AddRootNode(TreeView tree, ref int imageCount, ImageList imageList, ShellFolder shellFolder, bool getIcons) { Shell32.Shell shell32 = new Shell32.ShellClass(); Shell32.Folder shell32Folder = shell32.NameSpace(shellFolder); imageCount = AddRootNode(tree, imageCount, imageList, getIcons, shell32, shell32Folder, "Desktop"); }
/// <summary> /// Is link of the <paramref name="shortcutFilename"/> valid /// </summary> /// <param name="shortcutFilename">Shortcut file name</param> /// <returns>True if link of the <paramref name="shortcutFilename"/> valid</returns> public static bool IsLink(string shortcutFilename) { string pathOnly = Path.GetDirectoryName(shortcutFilename); string filenameOnly = Path.GetFileName(shortcutFilename); Shell shell = new ShellClass(); Folder folder = shell.NameSpace(pathOnly); FolderItem folderItem = folder.ParseName(filenameOnly); if (folderItem != null) { return folderItem.IsLink; } return false; // not found }
private static void AddRootNode2(TreeView tree, ref int imageCount, ImageList imageList, string shellFolder, bool getIcons) { Shell32.Shell shell32 = new Shell32.ShellClass(); Shell32.Folder shell32Folder = shell32.NameSpace(shellFolder); //shell32.BrowseForFolder(0, Path.GetFileName(shellFolder), 0, shellFolder); //shell32.NameSpace(shellFolder); imageCount = AddRootNode(tree, imageCount, imageList, getIcons, shell32, shell32Folder, Path.GetFileName(shellFolder)); }
/// <summary> /// Frees up managed resources /// </summary> /// <param name="disposing"></param> protected virtual void Dispose(bool disposing) { if( !disposing || shell == null ) return; Marshal.ReleaseComObject(shell); shell = null; }
public List<LinkType> LoadLinksFromStartup() { DirectoryInfo di = new DirectoryInfo(GetStartupPath()); FileInfo[] files = di.GetFiles("*DelayStartup.lnk"); List<LinkType> listOfLinks = new List<LinkType>(); foreach (FileInfo fi in files) { //parse link into string string pathOnly = Path.GetDirectoryName(fi.FullName); string filenameOnly = Path.GetFileName(fi.FullName); Shell32.Shell shell = new Shell32.ShellClass(); Shell32.Folder folder = shell.NameSpace(pathOnly); Shell32.FolderItem folderItem = folder.ParseName(filenameOnly); if (folderItem != null) { Shell32.ShellLinkObject link = (Shell32.ShellLinkObject)folderItem.GetLink; LinkType a = new LinkType(link,fi); listOfLinks.Add(a); } } return listOfLinks; }