[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4688: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4690: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4691: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4692: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
Poco Forums • View topic - Rename Attachments

Rename Attachments

Scripting questions and ideas

Moderators: Eric, Tomas, robin, Michael

Rename Attachments

Postby zero » Thu Apr 07, 2005 11:00 am

I'm trying to do something that I thought would be quite simple: Rename all attachments of a given extension.

Everything works except the actual rename. I can't figure out how to rename the files... Using Execute doesn't work, since it takes only up to 2 parameters, and I can't Execute, for example, "cmd.exe /c ren file.exe file.xxx".

I suppose I could Execute cmd.exe with a batch file, but then I'd have a command window flashing by every time a new message arrived. Not ideal.

Ideas, please?
zero
Poco Tourist
 
Posts: 28
Joined: Wed Dec 08, 2004 8:55 am

Postby Eric » Thu Apr 07, 2005 11:45 am

Have a look here. :wink:
Eric
 

Postby zero » Thu Apr 07, 2005 11:54 am

TYVM, but that sample script of Michael's appears to simply put up a msgbox that shows the name of attached files. Maybe I'm missing something...?
zero
Poco Tourist
 
Posts: 28
Joined: Wed Dec 08, 2004 8:55 am

Postby Eric » Thu Apr 07, 2005 12:00 pm

zero wrote:TYVM, but that sample script of Michael's appears to simply put up a msgbox that shows the name of attached files. Maybe I'm missing something...?


Michael wrote:The problem with solving this is that PocoScript does not have an native command for renaming files. You could use PocoScript to write a batch file to do this but that gets complicated.
:?
Eric
 

Postby zero » Thu Apr 07, 2005 12:03 pm

I know PocoMail has no native way to do it; that's why I was trying to use an external facility such as the rename command.
Last edited by zero on Fri Apr 08, 2005 1:21 pm, edited 1 time in total.
zero
Poco Tourist
 
Posts: 28
Joined: Wed Dec 08, 2004 8:55 am

Postby zero » Thu Apr 07, 2005 10:37 pm

Success!

I figured out a way to rename attachments (selectively, by a list of "hazardous" extensions), without an annoying command window flashing by.

It took a third-party utility and a goofy script trick or two, but I pulled it off.

The impetus for this script was that Michael Motek's "Attachment Killer" script was a nice idea, but I prefer to neuter attachments, rather than blindly delete them. (I realize that some personal firewall software does this, such as Outpost and ZoneAlarm, but I don't use them.)

I'll probably post the script when it's cleaned up.
zero
Poco Tourist
 
Posts: 28
Joined: Wed Dec 08, 2004 8:55 am

Postby zero » Fri Apr 08, 2005 8:52 pm

OK, if anyone could give this a whirl--either by just looking at it, or, better yet, by trying it--I'd really appreciate it. It's my first script, be gentle. :)

One caveat: The script requires the NirSoft NirCMD utility, and that the NirCMD.exe file be placed somewhere in your system or user path. NirCMD does not make any changes to your system!

Thanks to anyone adventurous enough to look at it.

<--- Click here to download the Attachment Renamer script --->
zero
Poco Tourist
 
Posts: 28
Joined: Wed Dec 08, 2004 8:55 am

Postby zero » Fri Apr 08, 2005 10:33 pm

0.9.1 - Updated to make the help file appear correctly when the list of extensions wasn't present.
0.9.2-0.9.3 - Prompts with help when "UserData1" text is missing; updated help HTML.
0.9.4 - A bunch of stuff. Mainly, you can now type "help" into a script configuration text box to have the script help file displayed.
zero
Poco Tourist
 
Posts: 28
Joined: Wed Dec 08, 2004 8:55 am

Postby zero » Sat Apr 09, 2005 1:26 pm

0.9.5 - Fixed problem with a mask like ".<whatever>" being specified as the rename text. Can now replace or append to existing extension.

Feedback, anyone?

I feel kind of silly here...
zero
Poco Tourist
 
Posts: 28
Joined: Wed Dec 08, 2004 8:55 am

Postby Pete » Sun Apr 10, 2005 11:06 am

I don't have time to look at your script (nor do I need that functionality) but there might be other interested people.

Nonetheless, I'm posting to say that you're right that the Execute command only accepts two arguments. However, the second argument can contain several space-separated values. For example:

Execute "cmd.exe" "/c ren \"c:\\my data\\oldname.txt\" \"c:\\my data\\newname.txt\""

Of course, this will give you the "black boxes", as you mentioned.
Last edited by Pete on Sun Apr 10, 2005 11:10 am, edited 1 time in total.
Pete
 

Postby zero » Sun Apr 10, 2005 11:09 am

Thanks. I made the rename command work, and did so without the annoying command windows flashing by.

So far, 6 people have downloaded the script. I think I'll just submit it when I have the chance.
zero
Poco Tourist
 
Posts: 28
Joined: Wed Dec 08, 2004 8:55 am

Postby Pete » Sun Apr 10, 2005 11:15 am

That's good. I'm not aware of any way to hide the command window that appears when people run DOS commands, except by using either a third-party utility or a self-written Windows program that wraps it.
Pete
 

Postby jaxgtr » Sun Apr 10, 2005 12:18 pm

Pete wrote:That's good. I'm not aware of any way to hide the command window that appears when people run DOS commands, except by using either a third-party utility or a self-written Windows program that wraps it.



To have an MS-DOS Batch file run in a hidden window:

In these circumstances, there is no MS-DOS window, nor any
corresponding Taskbar button, so the Batch Code should begin
@ECHO OFF and end with CLS and/or EXIT, or the process may
stall invisibly.

For example, if the Batch file to be run in a hidden window
is named C:\WORK\MYBATCH.BAT, create the following .VBS file:

====Begin cut-and-paste (omit this line)
CreateObject("Wscript.Shell").Run "C:\WORK\MYBATCH.BAT",0

====End cut-and-paste (omit this line)

Requires Windows Script Host installed. Double-click or otherwise
execute the .VBS file, for example, with the START command:

start MyFile.VBS

to run the Batch file invisibly.


Brian
jaxgtr
Poco Enthusiast
 
Posts: 439
Joined: Tue Aug 17, 2004 12:56 pm
Location: Jacksonville, FL

Postby zero » Sun Apr 10, 2005 12:25 pm

Cool! Thanks. I've filed that tidbit away for potential future use. I don't think I'll put it in this script, because it requires creating two additional files (the CMD and the VBS). I could put them in %temp% but... (Thinking about it.)
zero
Poco Tourist
 
Posts: 28
Joined: Wed Dec 08, 2004 8:55 am

Postby Pete » Sun Apr 10, 2005 11:58 pm

jaxgtr wrote:[...] create the following .VBS file:

====Begin cut-and-paste (omit this line)
CreateObject("Wscript.Shell").Run "C:\WORK\MYBATCH.BAT",0

====End cut-and-paste (omit this line)


Thanks, Brian. I would call that a "self-written Windows program that wraps it", but I must admit that I was thinking about a small C program or something. The VBS solution is a nice one, at least for people who use a modern version of Windows. As you said, however, this might require a separate download and installation for some people.
Pete
 

Next

Return to PocoScript Help and How-To

Who is online

Users browsing this forum: No registered users and 1 guest

cron