private void RenameFile(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(DocumentPath.Text) || string.IsNullOrWhiteSpace(NewFileName.Text))
            {
                MessageBox.Show(
                    "Please ensure that you've selected a file, and pressed PREVIEW FILENAME to extract the information");
                return;
            }

            try
            {
                _fileRenameService.RenameFile(DocumentPath.Text, NewFileName.Text);
            }
            catch (Exception)
            {
                MessageBox.Show("Something went wrong trying to rename file, make sure you haven't got that file opened");
            }
        }
Exemple #2
0
        public void RenameFileService(string folderPath)
        {
            var pdfFiles = _fileService.GetFiles(folderPath, "*.pdf");

            if (!pdfFiles.Any())
            {
                MessageBox.Show($"Can't find any pdf files in this folder: {folderPath}");
            }

            foreach (var pdfFilePath in pdfFiles)
            {
                try
                {
                    var extractedFields = _textExtractor.ExtractText(pdfFilePath);
                    var newFilename     = _fileRenameService.GetFileFormat(pdfFilePath, "TEST STATEMENT TYPE", extractedFields);
                    _fileRenameService.RenameFile(pdfFilePath, newFilename);
                }
                catch
                {
                    // ignored
                }
            }
        }