java
html
iphone
xml
ajax
database
ruby-on-rails
regex
objective-c
visual-studio
multithreading
silverlight
flash
json
algorithm
facebook
delphi
apache
mvc
postgresql
Sure. Here's how to write a batch script to do what you need done (in Python): Save it as runMogrify.py
import os import string import fnmatch source = "c:\\TEST\\import" target = "c:\\TEST\\export" def mogrify(parmSource, parmTarget): mkdirList = [] copyList = [] mogrifyList = [] mkdirList.append('mkdir "' + parmTarget + '"') for dirpath, dirnames, filenames in os.walk (parmSource): # print dirpath, dirnames, filenames for (index,file) in enumerate(sorted(filenames)): if fnmatch.fnmatch(file.lower(), '*.jpg') or \ fnmatch.fnmatch(file.lower(), '*.gif') or \ fnmatch.fnmatch(file.lower(), '*.bmp'): sourceFDirPathFile = dirpath + "\\" + file targetFDirPath = os.path.join (parmTarget, dirpath[1+len (parmSource):]) targetADirPathFile = targetFDirPath + "\\" + str(index+1) + "a" + os.path.splitext(file)[1] targetBDirPathFile = targetFDirPath + "\\" + str(index+1) + "b" + os.path.splitext(file)[1] if 'mkdir "' + targetFDirPath + '"' not in mkdirList: mkdirList.append('mkdir "' + targetFDirPath + '"') copyList.append('copy "' + sourceFDirPathFile + '" "' + targetADirPathFile + '"') copyList.append('copy "' + sourceFDirPathFile + '" "' + targetBDirPathFile + '"') mogrifyList.append('mogrify -resize 400x300 "' + targetADirPathFile + '"') mogrifyList.append('mogrify -resize 200x150 "' + targetBDirPathFile + '"') return mkdirList, copyList, mogrifyList def main(): mkdirList, copyList, mogrifyList = mogrify(source, target) f = open('RUNMOGRIFY.BAT', 'w') f.writelines( list("%s\n" % item for item in mkdirList ) ) f.writelines( list("%s\n" % item for item in copyList ) ) f.writelines( list("%s\n" % item for item in mogrifyList) ) f.close() if __name__=="__main__": main()
And, here's the resulting batch file (RUNMOGRIFY.BAT) after I ran the Python script above on a test directory similar to yours:
mkdir "c:\TEST\export" mkdir "c:\TEST\export\folder1" mkdir "c:\TEST\export\folder2" mkdir "c:\TEST\export\folder3" copy "c:\TEST\import\folder1\a.jpg" "c:\TEST\export\folder1\1a.jpg" copy "c:\TEST\import\folder1\a.jpg" "c:\TEST\export\folder1\1b.jpg" copy "c:\TEST\import\folder1\b.jpg" "c:\TEST\export\folder1\2a.jpg" copy "c:\TEST\import\folder1\b.jpg" "c:\TEST\export\folder1\2b.jpg" copy "c:\TEST\import\folder1\c.jpg" "c:\TEST\export\folder1\3a.jpg" copy "c:\TEST\import\folder1\c.jpg" "c:\TEST\export\folder1\3b.jpg" copy "c:\TEST\import\folder2\a.jpg" "c:\TEST\export\folder2\1a.jpg" copy "c:\TEST\import\folder2\a.jpg" "c:\TEST\export\folder2\1b.jpg" copy "c:\TEST\import\folder2\b.jpg" "c:\TEST\export\folder2\2a.jpg" copy "c:\TEST\import\folder2\b.jpg" "c:\TEST\export\folder2\2b.jpg" copy "c:\TEST\import\folder2\c.jpg" "c:\TEST\export\folder2\3a.jpg" copy "c:\TEST\import\folder2\c.jpg" "c:\TEST\export\folder2\3b.jpg" copy "c:\TEST\import\folder3\a.jpg" "c:\TEST\export\folder3\1a.jpg" copy "c:\TEST\import\folder3\a.jpg" "c:\TEST\export\folder3\1b.jpg" copy "c:\TEST\import\folder3\b.jpg" "c:\TEST\export\folder3\2a.jpg" copy "c:\TEST\import\folder3\b.jpg" "c:\TEST\export\folder3\2b.jpg" copy "c:\TEST\import\folder3\c.jpg" "c:\TEST\export\folder3\3a.jpg" copy "c:\TEST\import\folder3\c.jpg" "c:\TEST\export\folder3\3b.jpg" mogrify -resize 400x300 "c:\TEST\export\folder1\1a.jpg" mogrify -resize 200x150 "c:\TEST\export\folder1\1b.jpg" mogrify -resize 400x300 "c:\TEST\export\folder1\2a.jpg" mogrify -resize 200x150 "c:\TEST\export\folder1\2b.jpg" mogrify -resize 400x300 "c:\TEST\export\folder1\3a.jpg" mogrify -resize 200x150 "c:\TEST\export\folder1\3b.jpg" mogrify -resize 400x300 "c:\TEST\export\folder2\1a.jpg" mogrify -resize 200x150 "c:\TEST\export\folder2\1b.jpg" mogrify -resize 400x300 "c:\TEST\export\folder2\2a.jpg" mogrify -resize 200x150 "c:\TEST\export\folder2\2b.jpg" mogrify -resize 400x300 "c:\TEST\export\folder2\3a.jpg" mogrify -resize 200x150 "c:\TEST\export\folder2\3b.jpg" mogrify -resize 400x300 "c:\TEST\export\folder3\1a.jpg" mogrify -resize 200x150 "c:\TEST\export\folder3\1b.jpg" mogrify -resize 400x300 "c:\TEST\export\folder3\2a.jpg" mogrify -resize 200x150 "c:\TEST\export\folder3\2b.jpg" mogrify -resize 400x300 "c:\TEST\export\folder3\3a.jpg" mogrify -resize 200x150 "c:\TEST\export\folder3\3b.jpg"
Excuse me, perhaps I didn't completely understand your question; however, here are a couple Batch segments that may help you.
The first segment rename all folders existent in "import" to 1,2,3,etc and keep their original names in "name" vector. The process is easier if there is no left-zero in the numbers:
cd "C:\TEST\import" set i=0 for /D %%d in (*) do ( set /A i+=1 ren %%d !i! set name[!i!]=%%d )
Please note that you may process each 1,2,3,etc folders in "import" folder in the same FOR loop above using %%d for the name of the folder.
The second segment rename all folders in "export" to its original names stored by the first segment above:
cd "C:\TEST\export" for /D %%i in (*) do ( ren %%i !name[%%i]! )
If you use these segments in your program, you must include the next command at beginning:
setlocal EnableDelayedExpansion
Post any additional question if you have any doubt.