protected override void ProcessRecord() { string fname = StringHelpers.replaceTokens(_newPath, Context.Variables); PipeFile file = new PipeFile(); file.properties = new Variables(); file.properties.Add("filePath", fname); if (fname.IndexOf(@"\") > -1) { file.properties.Add("fileName", fname.Substring(fname.LastIndexOf(@"\"), fname.Length)); } else { file.properties.Add("fileName", fname); } file.properties.Add("filelastwritetime", DateTime.Now.ToShortTimeString()); StringBuilder sb = new StringBuilder(); foreach (PipeFile f in _files.Files) { sb.Append(f.Contents); } file.Contents = sb.ToString(); List <PipeFile> results = new List <PipeFile>(); results.Add(file); _files.Files = results; WriteObject(_files); }
protected override void ProcessRecord() { PipeFileSystem files = new PipeFileSystem(); string b = _base; if (b == null) { b = this.SessionState.Path.CurrentFileSystemLocation.Path; } if (!b.EndsWith(@"\")) { b = b + @"\"; } foreach (FileSystemInfo info in new Glob(StringHelpers.replaceTokens(Path.Combine(b, _pattern), Context.Variables)).Expand()) { PipeFile file = new PipeFile(); file.properties = new Variables(); file.properties.Add("fileFullname", info.Name); file.properties.Add("fileName", info.Name.Substring(0, info.Name.IndexOf("."))); string path = info.FullName.Replace(b, ""); file.properties.Add("filePath", path); file.properties.Add("fileExtension", info.Extension); file.properties.Add("fileLastWriteTime", info.LastWriteTime.ToShortTimeString()); WriteDebug("Reading file " + path); try { // Open the text file using a stream reader. using (StreamReader sr = new StreamReader(info.FullName)) { file.Contents = sr.ReadToEnd(); } } catch (Exception e) { Console.WriteLine("The file could not be read:"); Console.WriteLine(e.Message); } files.Files.Add(file); } WriteObject(files); }