0

I am looking to find a file with the contents 'Radiac' in one particular folder and then move all those files to a another folder.

For example: I have might have 3 identical file-names with different extensions like below. Let's say, the content Radiac is only in the jones.pdf file. What I want is a batch script that finds this specific content and then moves all the 3 file-names? I hope that makes sense. I'm new to windows batch scripting.

jones.pdf
jones.xml
jones.txt

How can I do this?

  • 1
    I think you would be better off with powerscript, python, or perl for this. You will also need to find a library or tool that can spit raw text out of a pdf. PDF is a specific format, not just text. This will be almost impossible to do with just batch. Seems like a stack overflow question to me. – Eddie Dunn Nov 30 '15 at 21:03
  • Hi Eddie, Thanks for the response. In this case, the .pdf document is searchable. However, to simplify things lets say it is the jones.txt file instead of the jones.pdf file. What I am looking to do is find the filename with this specific content then xcopy this filename.*.* and its associated extensions to another folder. – JohnNg Nov 30 '15 at 21:19
  • @B.Ng filename.*.* do you really mean this (It doesn't match your example filenames)? Or do you mean filename.*? – DavidPostill Dec 1 '15 at 9:20
1

If you want to use just batch and you are ok with the pdf support not being there.

Try This:

for /f "delims=" %%a in ('findstr /m /c:"Radiac" *') do xcopy "%%~na.*" "C:\path\to\your\folder"
  • I'm not sure how exactly to use this command. Do you mind explaining how it works? – JohnNg Nov 30 '15 at 21:39
  • It would probably be easiest to place the two lines in a .bat file and then run it from the directory that has the files you want to search. You will also need to change "c:\path\to\your\folder" to the path that you want the files to be copied into/ – Eddie Dunn Nov 30 '15 at 21:41
  • I have the 2 lines in the batch files. I've placed the batch file in the directory with the files I want to run. However, whenever I run it, I get "FINDSTR: Cannot open IN." IN is the directory with the files. – JohnNg Nov 30 '15 at 21:59
  • Hi Eddie, I appreciate the help. I changed the extension to include all files and it worked. For some reason StackExchange does not show asterisks. Now I just how to figure out copying files with the .pdf extension. – JohnNg Nov 30 '15 at 22:13
  • Ahh sorry about that! Glad you figured it out. – Eddie Dunn Nov 30 '15 at 22:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.