I wanted to share a work-around I found for the append problem above ...
Here is the main file:
client1="LastName_FirstName"
call change2jpg.bat
- client1="LastName_FirstName"
- call change2jpg.bat
This runs the batch script in the previous post to convert to jpgs.
set add_ext="_jpgs"
set "client1=%client1%%add_ext%"
- set add_ext="_jpgs"
- set "client1=%client1%%add_ext%"
( the batch file above saved the jpgs to a directory "LastName_FirstName_jpgs" )
dir /b /o:n c:\ghostscript\%client1% >> 2_filelist1.bat
This makes a bare list of the directory contents, just the names and nothing else. I wanted to append these line by line somehow to make another file with commands to move each file, but there doesn't seem to be a way to do that with just a batch file, so I wrote a Python script to do this:
"dot" = "." ( Ozzu thinks its a website, lol )
This script is at the end of this post. Basically it reads the directory listing line by line and asks which directory to move the file to, and writes a batch file with DOS commands to move to the appropriate directory ( by category ):
mkdir c:\ghostscript\%client1%\Category1
mkdir c:\ghostscript\%client1%\Category2
mkdir c:\ghostscript\%client1%\Category3
- mkdir c:\ghostscript\%client1%\Category1
- mkdir c:\ghostscript\%client1%\Category2
- mkdir c:\ghostscript\%client1%\Category3
Makes a subdirectory for each category.
This is the file made by the Python script. It would have something like:
move LastName_FirstName_pdf1_1_jpg c:\ghostscript\LastName_FirstName_jpgs\Category3\
move LastName_FirstName_pdf1_2_jpg c:\ghostscript\LastName_FirstName_jpgs\Category2\
move LastName_FirstName_pdf1_3_jpg c:\ghostscript\LastName_FirstName_jpgs\Category3\
(etc)
Then delete temporary files:
del c:\ghostscript\appended3.bat
del c:\ghostscript\2_filelist1.bat
- del c:\ghostscript\appended3.bat
- del c:\ghostscript\2_filelist1.bat
Here's the Python script from above:
client = "LastName_FirstName"
backs = chr(92)
dir1 = client + "_jpgs" + backs
dir2 = r" c:\ghostscript" + backs
dir3 = client + "_jpgs"
d = {}
fp = open("appended3.bat","w")
text_file = open("2_filelist1.bat", "r")
lines = text_file.readlines()
for line in lines:
if not line in d.keys():
d[line] = 0
d[line] = d[line] + 1
for line in lines:
line = line.replace("\n","")
print(line)
sort_option = input('Please enter a value:')
if sort_option == "1":
line_new = "move " + dir1 + line + dir2 + dir3 + "\Category1" + "\n"
if sort_option == "2":
line_new = "move " + dir1 + line + dir2 + dir3 + "\Category1" + "\n"
if sort_option == "3":
line_new = "move " + dir1 + line + dir2 + dir3 + "\Category1" + "\n"
line2 = line_new
fp.write(line2)
quit ()
- client = "LastName_FirstName"
- backs = chr(92)
- dir1 = client + "_jpgs" + backs
- dir2 = r" c:\ghostscript" + backs
- dir3 = client + "_jpgs"
- d = {}
- fp = open("appended3.bat","w")
- text_file = open("2_filelist1.bat", "r")
- lines = text_file.readlines()
- for line in lines:
- if not line in d.keys():
- d[line] = 0
- d[line] = d[line] + 1
- for line in lines:
- line = line.replace("\n","")
-
- print(line)
- sort_option = input('Please enter a value:')
- if sort_option == "1":
- line_new = "move " + dir1 + line + dir2 + dir3 + "\Category1" + "\n"
- if sort_option == "2":
- line_new = "move " + dir1 + line + dir2 + dir3 + "\Category1" + "\n"
- if sort_option == "3":
- line_new = "move " + dir1 + line + dir2 + dir3 + "\Category1" + "\n"
-
- line2 = line_new
- fp.write(line2)
- quit ()
It's kind of jenky right now, I'm going to work on it more, but it works and it's actually saved me a lot of time already.