private void DeleteFilesInDirectory(CodeActivityContext context) { try { string _directoryPath = DirectoryPath.Get(context); string _fileExtension = FileExtension.Get(context); int _dayCountFrom = Convert.ToInt16(DayCountFrom.Get(context)); int _dayCountTo = Convert.ToInt16(DayCountTo.Get(context)); bool _timestampCategory = Convert.ToBoolean((int)TimestampCategory); string[] fileList = Helper.DirectoryHelper.GetDirectoryFiles(directoryPath: _directoryPath, fileExtension: _fileExtension, timestampCategory: _timestampCategory, dayCountFrom: _dayCountFrom, dayCountTo: _dayCountTo); foreach (string file in fileList) { try { File.Delete(file); } catch (Exception ex) { throw ex; } } } catch (Exception ex) { if (Convert.ToBoolean((int)ContinueOnError)) { } else { throw ex; } } }
private void CopyFilesToDirectory(CodeActivityContext context) { try { string _directoryPathFrom = DirectoryPathFrom.Get(context); string _directoryPathTo = DirectoryPathTo.Get(context); string _fileExtension = FileExtension.Get(context); int _dayCountFrom = Convert.ToInt16(DayCountFrom.Get(context)); int _dayCountTo = Convert.ToInt16(DayCountTo.Get(context)); bool _timestampCategory = Convert.ToBoolean((int)TimestampCategory); bool _directoryAction = Convert.ToBoolean((int)DirectoryAction); bool _isNeedToReplace = Convert.ToBoolean((int)IsNeedToReplace); string[] fileList = Helper.DirectoryHelper.GetDirectoryFiles(directoryPath: _directoryPathFrom, fileExtension: _fileExtension, timestampCategory: _timestampCategory, dayCountFrom: _dayCountFrom, dayCountTo: _dayCountTo); //If directory isn't exists, it'll be created. if (!System.IO.Directory.Exists(_directoryPathTo)) { System.IO.Directory.CreateDirectory(_directoryPathTo); } foreach (string file in fileList) { try { string pathTo = Path.Combine(_directoryPathTo, Path.GetFileName(file)); if (_isNeedToReplace) { // Delete the exsisteing file if (File.Exists(pathTo)) { File.Delete(pathTo); } } if (_directoryAction) { File.Copy(file, pathTo); } else { File.Move(file, pathTo); } } catch (Exception ex) { throw ex; } } } catch (Exception ex) { if (Convert.ToBoolean((int)ContinueOnError)) { } else { throw ex; } } }