当前位置: 首页>>代码示例>>C#>>正文


C# FileInfo.LastIndexOf方法代码示例

本文整理汇总了C#中System.IO.FileInfo.LastIndexOf方法的典型用法代码示例。如果您正苦于以下问题:C# FileInfo.LastIndexOf方法的具体用法?C# FileInfo.LastIndexOf怎么用?C# FileInfo.LastIndexOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.FileInfo的用法示例。


在下文中一共展示了FileInfo.LastIndexOf方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FindLanguages

        internal static List<string> FindLanguages()
        {
            string[] a;
            var LstA = new List<string>();
            if (System.IO.Directory.Exists("Languages"))
            {
                a = System.IO.Directory.GetFiles("Languages", "*.ulex");
                foreach (var i in a)
                {
                    var u = new System.IO.FileInfo(i).Name;
                    u = u.Remove(u.LastIndexOf('.'));
                    LstA.Add(u);
                }
            }
            try
            {
                if (System.IO.Directory.GetFiles(Shared.LocalData("Languages")).Length > 0)
                {
                    a = System.IO.Directory.GetFiles(Shared.LocalData("Languages\\"), "*.ulex");
                    foreach (var i in a)
                    {
                        var u = new System.IO.FileInfo(i).Name;
                        u = u.Remove(u.LastIndexOf('.'));
                        if (LstA.Contains(u)) LstA.Remove(u);
                        LstA.Add(u);
                    }
                }
            }
            catch (Exception)
            {
                return LstA;
            }

            return LstA;
        }
开发者ID:RasyidUFA,项目名称:UFSJ,代码行数:35,代码来源:Shared.cs

示例2: LoadMessagesFromFiles

 public List<Message> LoadMessagesFromFiles()
 {
     var result = new List<Message>();
     try
     {
         foreach (var fileName in Directory.GetFiles(ExecutablePath.ExecPath + folder, "*.txt"))
         {
             var shortName = new FileInfo(fileName).Name;
             var roomName = shortName.Substring(0, shortName.LastIndexOf(".txt"));
             lock (fileLock)
             {
                 using (var fs = new FileStream(fileName, FileMode.OpenOrCreate))
                 using (var sr = new StreamReader(fs))
                 {
                     var lineNumber = 0;
                     while (true)
                     {
                         var line = sr.ReadLine();
                         if (string.IsNullOrEmpty(line))
                             break;
                         var words = line.Split(new[] {"&#32;"}, StringSplitOptions.None);
                         if (words.Length < 4)
                         {
                             Logger.Error(string.Format("LoadMessagesFromFiles: format error: file: {0}, line: {1}", fileName, lineNumber));
                             lineNumber++;
                             continue;
                         }
                         var message = new Message
                             {
                                 TimeStamp = DateTime.Parse(words[0]),
                                 Sender = words[1].ToInt(),
                                 Room = roomName,
                                 Receiver = words[2].ToInt(),
                                 Text = words[3].Replace("&#10;", Environment.NewLine)
                             };
                         result.Add(message);
                         lineNumber++;
                     }
                 }
             }
         }
     }
     catch (Exception exception)
     {
         Logger.Info("ChatClientStorage.LoadMessagesFromFiles", exception);
     }
     return result;
 }
开发者ID:johnmensen,项目名称:TradeSharp,代码行数:48,代码来源:ChatClientStorage.cs

示例3: InfoEFS

 public InfoEFS(string fichero)
 {
     string b = fichero.Substring (0, fichero.LastIndexOf('.'));
     string c = fichero.Substring (fichero.LastIndexOf('.')+1);
     if (b==String.Empty){
         // TODO: Poner una excepcion personalizada.
         throw new Exception ("...");
     }
     string tmp = new FileInfo (fichero).Name;
     tmp = tmp.Substring (0, tmp.LastIndexOf('.'));
     nombreOriginal = tmp;
     string nf = c.Substring (0, c.LastIndexOf("_")).Trim();
     string f = c.Substring (c.LastIndexOf ("_") + 1).Trim();
     Fragmento = Convert.ToInt32 (f);
     totalFragmentos = Convert.ToInt32 (nf);
 }
开发者ID:albfernandez,项目名称:dalle,代码行数:16,代码来源:InfoEFS.cs

示例4: Gen

        public static void Gen()
        {
            var outputDirPath = @"..\Json";//System.IO.Path.Combine( Application.StartupPath, "Output" );
            if (!Directory.Exists(outputDirPath))
            {
                try
                {
                    Directory.CreateDirectory(outputDirPath);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    Console.ReadKey();
                    return;
                }
            }
            foreach (var fn in Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "T_*.dll"))
            {
                var asm = Assembly.LoadFile(fn);
                var t = Helpers.GetTemplate(asm);
                var shortfn = new FileInfo(fn).Name;
                shortfn = shortfn.Substring(0, shortfn.LastIndexOf('.'));
                var path = outputDirPath;
                if (!Directory.Exists(path))
                {
                    try
                    {
                        Directory.CreateDirectory(path);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                        Console.ReadKey();
                        return;
                    }
                }

                var rtv = JsonGen.Gen(t, path, shortfn.Substring("T_".Length));
                if (rtv)
                {
                    Console.WriteLine(rtv.ToString());
                    Console.ReadKey();
                    return;
                }
            }
        }
开发者ID:captainl1993,项目名称:dbtocpp,代码行数:46,代码来源:GenJsonMG.cs

示例5: Main

        static void Main( string[] args )
        {
            var outputDirPath = System.IO.Path.Combine( Application.StartupPath, "Output" );
            if( !Directory.Exists( outputDirPath ) )
            {
                try
                {
                    Directory.CreateDirectory( outputDirPath );
                }
                catch( Exception ex )
                {
                    Console.WriteLine( ex.Message );
                    Console.ReadKey();
                    return;
                }
            }
            foreach( var fn in Directory.GetFiles( Application.StartupPath, "PacketTemplate_*.dll" ) )
            {
                var asm = Assembly.LoadFile( fn );
                var t = Helpers.GetTemplate( asm );
                var shortfn = new FileInfo( fn ).Name;
                shortfn = shortfn.Substring( 0, shortfn.LastIndexOf( '.' ) );
                var path = System.IO.Path.Combine( outputDirPath, shortfn.Replace( ".", "_" ) );
                if( !Directory.Exists( path ) )
                {
                    try
                    {
                        Directory.CreateDirectory( path );
                    }
                    catch( Exception ex )
                    {
                        Console.WriteLine( ex.Message );
                        Console.ReadKey();
                        return;
                    }
                }

                var rtv = GenCPP.Gen( t, path, shortfn.Substring( "PacketTemplate_".Length ) );
                if( rtv != "" )
                {
                    Console.WriteLine( rtv );
                    Console.ReadKey();
                    return;
                }
            }
        }
开发者ID:whuthj,项目名称:69net,代码行数:46,代码来源:Program.cs

示例6: GetFromFile

        public static JoinInfo GetFromFile(string fichero)
        {
            JoinInfo info = new JoinInfo ();
            info.Directory = new FileInfo (fichero).Directory;
            string original = new FileInfo (fichero).Name;
            string extensionParte = original.Substring (original.LastIndexOf (".")+1);
            info.BaseName = original.Substring (0, original.LastIndexOf ('.') + 1);
            info.OriginalFile = original.Substring (0, original.LastIndexOf ('.'));

            // Soporte ultrasplit
            if (extensionParte.StartsWith ("u")) {
                info.BaseName = original.Substring (0, original.LastIndexOf ('.') + 2);
            }
            info.Digits = original.Length - info.BaseName.Length;

            if (File.Exists (info.Directory.FullName + Path.DirectorySeparatorChar + info.BaseName + UtilidadesCadenas.Format (0, info.Digits)))
            {
                info.InitialFragment = 0;
            }
            else if (File.Exists (info.Directory.FullName + Path.DirectorySeparatorChar + info.BaseName  + UtilidadesCadenas.Format (1, info.Digits)))
            {
                info.InitialFragment = 1;
            }
            else {
                return null;
            }
            int contador = 1;

            while (File.Exists (info.GetFragmentFullPath (contador)))
            {
                FileInfo fi = new FileInfo (info.GetFragmentFullPath (contador));
                info.Length += fi.Length;
                contador++;
            }
            info.FragmentsNumber = contador - 1;

            // Comprobar cutkiller
            if (info.InitialFragment == 1 && info.Digits == 3)
            {
                byte[] buffer = UtilidadesFicheros.LeerSeek (info.GetFragmentFullPath(1), 0, 8);
                string extension = UtArrays.LeerTexto (buffer, 0, 3);
                string fragmentos = UtArrays.LeerTexto (buffer, 3, 5);
                if (extension.Length > 0 && fragmentos.Length == 5)
                {
                    if (
                        Char.IsWhiteSpace (fragmentos[0]) &&
                        Char.IsWhiteSpace (fragmentos[1]) &&
                        Char.IsDigit (fragmentos[2]) &&
                        Char.IsDigit (fragmentos[3]) &&
                        Char.IsDigit (fragmentos[4]) &&
                        Int32.Parse (fragmentos.Trim ()) == info.FragmentsNumber

                    )
                    {
                        info.IsCutKiller = true;
                        info.OriginalFile = info.OriginalFile + "." + extension;
                        info.Length -= 8;
                    }
                }
            }
            info.CalculateLength();
            return info;
        }
开发者ID:albfernandez,项目名称:dalle,代码行数:63,代码来源:JoinInfo.cs

示例7: AddProjectInclude

        public async Task<bool> AddProjectInclude(string containerDirectory, string scriptFile = null)
        {
            if (!Project.Saved)
            {
                var saveDialogResult = MessageBox.Show(_ownerWindow, "Save pending changes to solution?",
                    "Save pending changes", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (saveDialogResult == DialogResult.OK || saveDialogResult == DialogResult.Yes)
                    _dte.SaveAll();
            }
            if (!Project.Saved || string.IsNullOrEmpty(Project.FullName))
            {
                var saveDialogResult = MessageBox.Show(_ownerWindow, "Pending changes need to be saved. Please save the project before adding project imports, then retry.", "Save first",
                    MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk);
                if (saveDialogResult != DialogResult.Cancel) _dte.SaveAll();
                return false;
            }
            _logger.LogInfo("Begin adding project import file");
            if (string.IsNullOrWhiteSpace(containerDirectory))
                containerDirectory = Project.GetDirectory();

            if (string.IsNullOrWhiteSpace(scriptFile))
            {
                _logger.LogInfo("Prompting for file name");
                var dialog = new AddBuildScriptNamePrompt(containerDirectory, ".targets")
                {
                    HideInvokeBeforeAfter = true
                };
                var dialogResult = dialog.ShowDialog(VsEnvironment.OwnerWindow);
                if (dialogResult == DialogResult.Cancel) return false;
                scriptFile = dialog.FileName;
                _logger.LogInfo("File name chosen: " + scriptFile);
                dialogResult = MessageBox.Show(_ownerWindow, @"        !! IMPORTANT !!

You must not move, rename, or remove this file once it has been added to the project. By adding this file you are extending the project file itself. If you must change the filename or location, you must update the project XML directly where <Import> references it.",
                    "This addition is permanent", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                if (dialogResult == DialogResult.Cancel) return false;
            }
            var scriptFileName = scriptFile;
            if (!scriptFile.Contains(":") && !scriptFile.StartsWith("\\\\"))
                scriptFile = Path.Combine(containerDirectory, scriptFile);
            var scriptFileRelativePath = FileUtilities.GetRelativePath(Project.GetDirectory(), scriptFile);
            var scriptFileShortName = new FileInfo(scriptFile).Name;
            if (scriptFileShortName.Contains("."))
                scriptFileShortName = scriptFileShortName.Substring(0, scriptFileShortName.LastIndexOf("."));

            if (Project == null) return false;

            File.WriteAllText(scriptFile, @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
    <Target Name=""" + scriptFileShortName + @"""><!-- consider adding attrib BeforeTargets=""Build"" or AfterTargets=""Build"" -->

        <!-- my tasks here -->
        <Message Importance=""high"" Text=""" + scriptFileShortName + @".targets output: ProjectGuid = $(ProjectGuid)"" />

    </Target>
</Project>");
            var projRoot = Project.GetProjectRoot();
            var import = projRoot.AddImport(scriptFileRelativePath);
            import.Condition = "Exists('" + scriptFileRelativePath + "')";
            Project = await Project.SaveProjectRoot();
            var addedItem = Project.ProjectItems.AddFromFile(scriptFile);
            addedItem.Properties.Item("ItemType").Value = "None";
            _logger.LogInfo("Project include file added to project: " + scriptFileName);
            Task.Run(() =>
            {
                System.Threading.Thread.Sleep(250);
                _dte.ExecuteCommand("File.OpenFile", "\"" + scriptFile + "\"");
            });
            return true;
        }
开发者ID:freeart,项目名称:FastKoala,代码行数:69,代码来源:TargetsScriptInjector.cs

示例8: GetSelectedText

        private void GetSelectedText()
        {
            int activeWinPtr = GetForegroundWindow().ToInt32();
               int activeThreadId = 0, processId;
               activeThreadId = GetWindowThreadProcessId(activeWinPtr, out processId);
               int currentThreadId = GetCurrentThreadId();
               //String prev = txtCmdLine.Text;
               if (activeThreadId != currentThreadId)
               {
               AttachThreadInput(activeThreadId, currentThreadId, true);
               SendCtrlC();
               System.Threading.Thread.Sleep(10);
               AttachThreadInput(activeThreadId, currentThreadId, false);
               ShowHide();
               if (Clipboard.ContainsText())
               {
                        HandleCmd(CmdInvoker.InvokeCommand("a "+Clipboard.GetText().Replace(Environment.NewLine," ")));
               }
               else if (Clipboard.ContainsFileDropList())
               {
                   for (int i = 0; i < Clipboard.GetFileDropList().Count; i++)
                   {
                       GGResult r;
                       String f = new FileInfo(Clipboard.GetFileDropList()[i]).Name;
                       if (f.Contains('.')) f = f.Substring(0, f.LastIndexOf('.'));
                       r = CmdInvoker.InvokeCommand("a \"" + f + "\"");
                       GGItem gg = CmdInvoker.GetGGList().GetGGItemAt(r.GetItemIndex());
                       HandleCmd(r);
                       HandleCmd(CmdInvoker.InvokeCommand("pin " + (CmdInvoker.GetGGList().IndexOfGGItem(gg) + 1) + " " + Clipboard.GetFileDropList()[i]));

                   }
               }
               //if (txtCmdLine.Text.Equals("a ")) txtCmdLine.Text = prev;
               }
        }
开发者ID:wertkh32,项目名称:gg,代码行数:35,代码来源:MainWindow.xaml.cs

示例9: GetUniqueCartesianProduct

        private static IEnumerable<int[]> GetUniqueCartesianProduct(string testName)
        {
            var files = Directory.GetFiles(string.Format(@"D:\test\MUTEX\CompleteComparison\sources\{0}", testName),
                                           @"main.c", SearchOption.AllDirectories).Select(p =>
                                                                                              {
                                                                                                  var dn =
                                                                                                      new FileInfo(p).
                                                                                                          DirectoryName;
                                                                                                  return
                                                                                                      Int32.Parse(
                                                                                                          dn.Substring(
                                                                                                              dn.LastIndexOf(
                                                                                                                  '\\') + 1));
                                                                                              }).ToList();

            var cp = from first in files
                     from second in files
                     orderby first , second
                     select new[] {first, second};

            var cartesianProduct = cp.Where(elem => elem[0] < elem[1]).ToList();
            return cartesianProduct;
        }
开发者ID:yas4891,项目名称:MUTEX,代码行数:23,代码来源:CompleteComparisonReport.cs

示例10: GetSourceMatchesGenerateZipFilePath

 public void GetSourceMatchesGenerateZipFilePath(LeanDataLineTestParameters parameters)
 {
     var source = parameters.Data.GetSource(parameters.Config, parameters.Data.Time.Date, false);
     var normalizedSourcePath = new FileInfo(source.Source).FullName;
     var zipFilePath = LeanData.GenerateZipFilePath(Globals.DataFolder, parameters.Data.Symbol, parameters.Data.Time.Date, parameters.Resolution, parameters.TickType);
     var normalizeZipFilePath = new FileInfo(zipFilePath).FullName;
     var indexOfHash = normalizedSourcePath.LastIndexOf("#", StringComparison.Ordinal);
     if (indexOfHash > 0)
     {
         normalizedSourcePath = normalizedSourcePath.Substring(0, indexOfHash);
     }
     Assert.AreEqual(normalizeZipFilePath, normalizedSourcePath);
 }
开发者ID:kaffeebrauer,项目名称:Lean,代码行数:13,代码来源:LeanDataTests.cs


注:本文中的System.IO.FileInfo.LastIndexOf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。