Esempio n. 1
0
        public static List <LogInfo> DirSize(EngineState s, CodeCommand cmd)
        {
            List <LogInfo> logs = new List <LogInfo>();

            Debug.Assert(cmd.Info.GetType() == typeof(CodeInfo_DirSize));
            CodeInfo_DirSize info = cmd.Info as CodeInfo_DirSize;

            string dirPath = StringEscaper.Preprocess(s, info.DirPath);

            if (Directory.Exists(dirPath) == false)
            {
                logs.Add(new LogInfo(LogState.Error, $"Directory [{dirPath}] does not exist"));
                return(logs);
            }

            string[] files   = FileHelper.GetFilesEx(dirPath, "*", SearchOption.AllDirectories);
            long     dirSize = 0;

            for (int i = 0; i < files.Length; i++)
            {
                FileInfo fileInfo = new FileInfo(files[i]);
                dirSize += fileInfo.Length;
            }

            logs.Add(new LogInfo(LogState.Success, $"Directory [{dirPath}] is [{dirSize}B]", cmd));

            List <LogInfo> varLogs = Variables.SetVariable(s, info.DestVar, dirSize.ToString());

            logs.AddRange(varLogs);

            return(logs);
        }
Esempio n. 2
0
        public static List <LogInfo> DirSize(EngineState s, CodeCommand cmd)
        {
            List <LogInfo> logs = new List <LogInfo>();

            CodeInfo_DirSize info = cmd.Info.Cast <CodeInfo_DirSize>();

            string dirPath = StringEscaper.Preprocess(s, info.DirPath);

            if (!Directory.Exists(dirPath))
            {
                return(LogInfo.LogErrorMessage(logs, $"Directory [{dirPath}] does not exist"));
            }

            string[] files   = FileHelper.GetFilesEx(dirPath, "*", SearchOption.AllDirectories);
            long     dirSize = files.Sum(f => new FileInfo(f).Length);

            logs.Add(new LogInfo(LogState.Success, $"Directory [{dirPath}] is [{dirSize}B]", cmd));

            List <LogInfo> varLogs = Variables.SetVariable(s, info.DestVar, dirSize.ToString());

            logs.AddRange(varLogs);

            return(logs);
        }