Well, here's a solution based on what you've explained. It will get the directory listing for two directories and match based on alphabetical match. Unless you have a mapping (maybe something inside the file1.html to indicate what it should be?) this is the best I can guess at.
D1
file1.html
file2.html
file3.html
file4.html
file5.html
file6.html
D2
annoy.html
fastFurious.html
fastFurious2.html
index.html
postinfo.html
_vti_inf.html
Step 1, Install
Python. Reboot if neccesary.
Step 2, Copy the following code and save it out (use textpad or notepad) as C:\directoryFixer.py
Step 3, Change the locations in the following script to match your file structure.
Step 4, At the command prompt (either cmd or command depending on your version of Windows)
C:\>python c:\directoryFixer.py
Manually adjust files based on any warnings
Code: Select all
import os
import glob
import shutil
def getFilesInDirectory(directory, pattern = "*.*"):
"""
Get a listing for a particular directory
"""
return glob.glob1(directory, pattern)
def mkdir(path):
"""
Make the directory structure if needed.
"""
#test to see if the path exists
if (not os.path.exists(path)):
# if not, try and make it.
try:
os.makedirs(path)
except os.error, value:
#If fail (due to permission or whatever, bomb out I guess)
print value[0], value[1]
except:
print "Bad mojo - failed to make directories and such"
return
def main():
#these lists will hold the name of the files
directory1 = []
directory2 = []
#the r mean raw string which is needed to allow the backslashes (\)
# to be used as is
d1Location = r"C:\Inetpub\wwwroot\directory1"
d2Location = r"C:\Inetpub\wwwroot\directory2"
d3Location = r"C:\Inetpub\wwwroot\directory3"
#if you need htm files as well, change the pattern
directory1 = getFilesInDirectory(d1Location, "*.html")
directory2 = getFilesInDirectory(d2Location, "*.html")
mkdir(d3Location)
#for each file in directory1, save it out to d3 under the name in directory2
#this assumes the order of files in d1 and d2 match each other
i = 0
for f in directory1:
try:
print "copy " + f + " to " + directory2[i]
shutil.copyfile(os.path.join(d1Location, f), os.path.join(d3Location, directory2[i]))
i += 1
except:
print "failed to copy " + f + "\nProbably cause --- no matching file in second directory"
if __name__ == '__main__':
main()