Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

2 Answers

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
add comment
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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