Recursively Add Files to Your Perforce Depot
Mon Apr 24, 15:51
I'm using Perforce on Windows (neither by choice) and apparently Perforce doesn't have a mechanism to recursively add files to the depot. I have a couple thousand files I want to put under version control, so doing it by hand is not an option, and shell scripting in Windows is unbearable. If I was using Subversion I could just do svn add * -r but I can't find anything like that for Perforce.
So, if you have a solution please let me know. Otherwise I'll have to use this ruby script I cooked up. I'm pretty sure it does the job:
#!ruby -w
# Recursively add files to Perforce depot. Apparently there isn't another way.
# Run this script in the directory that you want to add.
root = Dir.pwd
puts `p4 add -f *`
Dir["**/*/"].each { |dir|
Dir.chdir "#{root}\\#{dir}"
puts `p4 add -f *`
}
In case you're wondering, **/*/ recursively matches all the directories under this one. Also, the puts is in there to print out what the p4 add command outputs. If you don't want to see it, then just do `p4 add -f *`.