Can anyone write a macro or script for me.
This is a brief explanation...
STEP 1:
======
I create new web pages and put them in Folder A.
I open all the pages in this folder with TextPad.
These web pages can be .html or .htm or .shtml and the names could be random e.g.
- doc1.html
- doc2.html
- document3.html
- files.html etc.
STEP 2:
=======
I have a number of previously created web pages in Folder B and these have specific names e.g.
- herbal.html
- low-cal.html
- chrom-picol.html
- ibsherbals.html etc.
What I need the script to do is for it to copy the new pages from Folder A and place them into either Folder B where they overwrite the existing web pages or better still, places these web pages from Folder A into a new folder (Folder C) but changes the names to those of the web pages found in Folder B.
This is a challange - can anyone do this?
I am willing to pay a fee.
Thanks
Craig
Need help from someone with brains
Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard
- talleyrand
- Posts: 624
- Joined: Mon Jul 21, 2003 6:56 pm
- Location: Kansas City, MO, USA
- Contact:
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
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()
I choose to fight with a sack of angry cats.