232bird opened this issue on Mar 22, 2011 · 18 posts
232bird posted Tue, 22 March 2011 at 2:41 AM
In light of this problem I created a batch file to search through a specified folder tree, grab all files of a specified type, and copy them to another folder while adding the relative file path to the file name. For example, the program as posted will search recursively down from the folder in which it is located for all PNG files, copy them to cresults, and add the relative file path to the file name. I then look through the pictures for shoes, copy those pictures to a "Shoes" directory, and then use that information to either organize my physical runtime folders, or just as a guide to find what I am looking for, since the file name includes the path of the original file.
The program is fairly simple to use, but first the ugly parts:
I posted it as a batch for file for three reasons
1 - My programming knowledge is limited, so to "real" programmers please have a good laugh about it, but don't post how I could have done it better with C++ or Python or VB or FORTRAN (LOL) unless you are VERY descriptive and willing to help proceed along that path.
2 - In very rare cases it may be neccessary to run the file as an administrator, or an antivirus might blow up over it (although I can't imagine a scenario that would cause either). If that is the case, don't complain to me about it, just look at the text and decide for yourself if it is harmful or not.
3 - It would be inexcusably stupid for me to compile something so basic into a proprietary EXE when it is nothing special and I want it to evolve. With that said, if anybody wants to add to it please do so, I only ask that you do it here so everybody can benefit.
I have some modifications to this script I am working on, to allow for on-the-fly user input for the paths and file types, as well as the ability to save out and read from configuration files. I also have a handful of other scripts I wrote that I use all the time that I want to incorporate with this into a big master program, but I am only willing to do that if a) anybody actually cares and wants it, and b) people tell me what they want. This will never be as powerful as D3D's tools, but helps automate some of the time-consuming tasks of dealing with Poser and it's offspring programs.
To use, just download the txt file and rename the .txt to .bat. Place it in the top of the folder tree to analyze. For example, to analyze the characters folder and its sub-folders, place the file in the characters folder. To analyze and entire runtime, just place the file in that runtime folder.
- Next, open the file in a text editor. For the line "set results=c:", just change the c: to whatever path you want the results folder to be placed in. And for the "set file=png" line, change png to whatever file extension you want to search for. Sorry I couldn't figure out how to get a screenshot in, but they are lines 6 and 7.
- Save the file, and run it. It will give a message in the CMD window when it is complete, as well as write a log file to whatever folder it is in.
Bugs:
- The script may give the error "The filename, directory name, or volume label syntax is incorrect." This is because Windows Command Prompt sees "!" in a file or folder name as a special character (devs love to name there runtime folders !something), and will not include it in the folder name, therefore any files in that folder will not be copied. If anybody knows a solution to this, PLEASE let me know. For the time being, look through or search the log.txt file for "The system cannot find the path specified." to find the culprit folder.
- Not really a bug, but the script writes and deletes a file "copy.bat" as needed. If the script is aborted before that file is deleted, it will obviously remain in the same folder as the script. it is OK to delete it since it is no longer used, or just run the script again and that file will be overwritten and deleted anyway.
This program should run on any system with Windows XP or later, but since the command prompt has evolved then digressed then evolved again over time I think anything XP SP3 or newer is guaranteed to work. I have only used it on Win7 so far.
Again, I have some other programs i wrote, such as copying commonly used paths to the clipboard (for example instead of browsing through folder after folder.... in Morphing Clothes or the like), or doing runtime backups. I can polish those for public use or include them in this, but only if anybody cares. For now this can be an ice-breaker.
ockham posted Tue, 22 March 2011 at 6:56 AM
Extremely clever.
I still use BATs sometimes, because I use one of those Norton Commander progs for all file and folder action, and BATs are comfortable in that environment. But I didn't realize BAT-language had become so sophisticated!
I doubt it could be done anywhere near as succinctly in Python or Fortran!
Would like to see more.
232bird posted Tue, 22 March 2011 at 11:44 PM
Thanks for the encouragement Ockham, love your work by the way. I can put up my script to send paths to the clipboard, just need to made it deployable first. And I have to figure out how best to go about that so everybody can use it easily.
SteveJax posted Wed, 23 March 2011 at 3:20 AM
I try to avoid batch processing for most things that are location sensitive.
232bird posted Thu, 24 March 2011 at 2:21 AM
Yup, I understand. That's exactly why I built in the variables for folder paths.
Acadia posted Thu, 24 March 2011 at 3:57 AM
Interesting.
However, I still think I'll stick with my tried and true method.
To install: I locate the original zip or .exe file. Unpackage it into a folder on my desk top. Go through the folders and rearrange / organize the files in the main library folders, and then rename the folders for continuity throughout all of the library folders. Then I move the unpackaged runtime to the external runtime of my choice.
To uninstall: I unpackage the original zip or .exe into a polder on my desk top. Locating the files for the package in my main library folder is easy. The reason I unpackage the original file again is to locate the morphs, geometries and texture files which are typically installed using some weird kind of archive method that I've yet to figure out: It's not always by item name or even vendor name!!!
It does take some time, but I don't typically uninstall stuff once it is installed.
"It is good to see ourselves as
others see us. Try as we may, we are never
able to know ourselves fully as we
are, especially the evil side of us.
This we can do only if we are not
angry with our critics but will take in good
heart whatever they might have to
say." - Ghandi
Acadia posted Thu, 24 March 2011 at 4:02 AM
Hmmm. I just read your post closer. Now I'm confused. I thought the program automatically moved things around, but I see it actually just lists the content of a folder and it's sub folders, is that correct? If so that could be a very valuable tool.
"It is good to see ourselves as
others see us. Try as we may, we are never
able to know ourselves fully as we
are, especially the evil side of us.
This we can do only if we are not
angry with our critics but will take in good
heart whatever they might have to
say." - Ghandi
232bird posted Thu, 24 March 2011 at 3:19 PM
Quote - Hmmm. I just read your post closer. Now I'm confused. I thought the program automatically moved things around, but I see it actually just lists the content of a folder and it's sub folders, is that correct? If so that could be a very valuable tool.
Sort of. It copies all the target file types from the targetted folder tree to a new folder, while adding the relative file path to the file name. I did that instead of just a file list so I can visually go through my content. And since the filename now includes the path, once I find the thumbnail of what I am looking for I will have the path in the filename, so I know where to look in my runtime. Or I can use that path to file the file and rearrange the runtime, but I haven't gotten that far. Been spending all my time on the scripts, lol.
lmckenzie posted Thu, 24 March 2011 at 9:43 PM
A neat idea and very concisely implemented. I use Acadia's approach for installing content, though for various reasons, I leave the original archive structure as it is. Eventually, I plan to record install information in my archive database to allow one click uninstallation - though, like her, I seldom uninstall anything :-) I know there are some Poser install utilities that do this, but I haven't tried any of them.
P3DO provides a good visual catalog of runtime contents. In the detail view, it will even list the geometry and texture files associated with a .cr2 etc. The main imitation, especially if you move/rename files is that you don't know where all the associated MAT/MTL files etc. AFAIK, are unless you record that information at install time, either in the archive or by some other means.
If you ever encounter the need to add sorting/querying etc. to your projects, look at SQLite, an excellent database that has a command line interface which would probably work well in a batch environment. http://www.sqlite.org/
"Democracy is a pathetic belief in the collective wisdom of individual ignorance." - H. L. Mencken
vholf posted Thu, 24 March 2011 at 9:52 PM
Whoa, I can understand C, python, even Lisp, but there's a few lines there I can't entirely figure out just by looking at it.
Nice work, and quite a good idea, I do something similar myself.
232bird posted Fri, 25 March 2011 at 1:12 AM
Thanks Hioshi. It did take me a while to figure out how to use changing variables in FOR loops, I think that's what you are referring to.
I have another one on the way, just need to get it ready for deployment. I'll have it up later on today.
232bird posted Fri, 25 March 2011 at 6:29 PM
I looked at it, and agree with you on the benefits. I want to get to the point eventually where I can write actual programs, but for the time being I'm still just stumbling through batch files.
So the good news, I have another one. It copies a path (or any information entered, for that matter) to the clipboard. This one has a setup so no need to edit the script. Just download the file and rename .txt to .bat as before. Run it, and it will prompt you for the info it needs, first the name you want to assign to the slot, then the path for that respective slot. After you are finished entering the information, it will create a new batch file which will be the main program. Run it, and select whichever slot from the menu you want to copy to the clipboard.
Example: I make a character, and want to transfer the FBM to a clothing item. In the setup I would enter "My Characters" as the slot name, and "C:runtimeslibrariescharactermy characters" as the path. Then I can open Morphing Clothes, copy the path with the program, and paste the path into the location bar in MC, instead of having to browse through all the folder levels to get to what I want.
vholf posted Sun, 27 March 2011 at 3:12 PM
Another nice one, I do find myself browsing around when using Morphing Clothes.
If you enjoy writing short scripts like this, you should really take a look at python, you'll love it. You could wrap all that inside a single "for" statement.
232bird posted Mon, 28 March 2011 at 6:04 AM
A couple things to note:
- The script will NOT harm your original pz3, it only copies it and works on the copy.
- Because of this, it is best to have at least twice the disk space available as the room your pz3s take up. (Don't worry, it will delete the working file after every cycle of the loop so things don't get out of hand)
- The script works fine with long filenames, but will not work with folder names that have spaces in them. I don't know why, and eventually lost patience with trying to debug it. Just keep that in mind, and rename folders if necessary.
- Since the original pz3 remains, it wouldn't be a bad idea to verify the new files before you delete the old ones. I haven't had any problems, but just thought I should say it.
- The compression level I used seems to be around %10 better than Poser's. I left it at 7/10 because anything higher resulted in a substancial increase in compression time, with only a minimal decrease of file size.
Hioushi, you are %100 correct. It gave me all kinds of fits with the long folder names and renaming files from within the FOR loop. Time for me to learn Python.
vholf posted Mon, 28 March 2011 at 8:28 AM
Don't quote me on this, but I believe Poser's zip format is actually different than the standard zip, so using 7zip to compress the files might not be such a good idea. Like I said, I could be wrong, but I remember someone mentioning here in the forums the header was a little different, even though it seems to compress and decompress fine, there's a chance the file could end up not working anymore.
Also, Poser already comes with a script for compressing files, and it works recursively on any directory you point it to. Any particular reason why you are not using that script?
As for python, well I can see you are quite comfortable with batch scripting, but I only mention it because it could significantly speed up your work. Take a look at the following example to print the name of all files inside a directory (recursively).
import os
for root,dirs,files in os.walk("C:SomePathWithProperPermissions"):
print files
lmckenzie posted Mon, 28 March 2011 at 11:10 AM
Attached Link: AutoIt
I believe it's gzip which you can download free. I call it myself from within a program. To decompress - (text after ' is a comment):gzip -d -a -f
On the spaces, you're going to have to enclose such folder names in quotes e.g. from the command line:
dir C:Program Files
dir C:"Program Files"
Not sure how to do that automatically without requiring the user to quote the entries in a bat file.
You might also look at AutoIt, which will give you the ability to work with windows, automate programs etc. You already understand logic and control flow so picking up programming with Autoit, VBScript, Python etc. should be no problem. I encourage you to pursue it.
"Democracy is a pathetic belief in the collective wisdom of individual ignorance." - H. L. Mencken
232bird posted Mon, 28 March 2011 at 12:14 PM
Quote - Also, Poser already comes with a script for compressing files, and it works recursively on any directory you point it to. Any particular reason why you are not using that script?
Hah! Because I had no idea it was even their. Thanks!
232bird posted Tue, 29 March 2011 at 12:10 AM
I know, that's the wrong spelling of there. It won't let me edit.