Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to execute a script to compile all pdfs into a single folder. My target folder may have the file already. I want to create a script that searches another set of directories for *.pdf and copy them to target, however if the file already exist in the target just delete the source file and leave the target file alone. Is there a way to efficiently script this?

share|improve this question
1  
Would you be open to using PowerShell? Though I'm sure it can be done in Batch, I'm also confident someone else here has a better solution in PS. Since it comes built-in to Windows 7, I highly recommend you try it out. – Iszi Aug 16 '11 at 14:12
    
That would be fine. That is to say I'm not opposed to it. I'll do some more googling – MVCylon Aug 16 '11 at 14:21
    
If you already have experience with any of Perl, Python, or Ruby, this is a perfect use case for one of those languages, as they each have a much more robust set of tools for managing files than Batch scripts. – asfallows Aug 16 '11 at 14:45
1  
The simplest solution would be batch or powershell as Iszi suggested, though any scripting language could do this easily (perl, python, ruby as suggested by asfallows, but also autoit). – MaQleod Aug 16 '11 at 14:56
    
Of course, there's always good ol' C-x M-c M-butterfly... – Iszi Aug 16 '11 at 16:28

I think you might be able to do that with robocopy and the right combination of arcane flags but I'd recommend some serious testing.

share|improve this answer
IF EXIST filename (
del filename
) ELSE (
mv filename targetpath
)

I found this example from this website. You could nest this in a loop which iterates over whatever set of directories you like, passing the filenames into the IF one by one.

share|improve this answer
    
Sounds like a FOR or FOR /F loop may be what's needed here. Not sure how you'd like to pass the filename between FOR and IF though. – Iszi Aug 16 '11 at 16:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .