Jump to content

would like a script for tagging files as readonly after completion


Recommended Posts

Edit: I'll sum up here the answer I got from Ultima if you don't want to read the entire thread

How to have your downloaded files get the readonly flag after the torrent finishes downloading:

- On the torrent in main window, right-click -> properties, advanced tab, there's a field "Run this program when the torrent finishes"

- Put there cmd /c attrib +R "%D\%F*" /S /D. First time paste it, later utorrent will remember it in the drop-down arrow, immediately right of the field.

- Action is performed after the move, so you can use the "Move completed download to:" feature if you like

- This is a simple one line, so it doesn't work in some (unlikely?) cases, read caveats below.

- There's a console window quickly popping up and closing on completion. Use /k instead of /c if you want that window to stay open... there won't be any useful info printed on that window though.


Tested on Vista with 1.7.7 on multifile torrents

Files don't get the readonly attribute on completion individually, only when the whole torrent finishes downloading

The action is not exactly performed on the torrent files, but rather

- for multifile-torrents, on all files (and folders) in the torrent folder

- and for single file torrents, e.g. foo.bar, on all foo.bar* files in the same folder, e.g. foo.barup.wiz.

(this all happens after files are moved if you use that feature)

Thus more files than intended could be made readonly in some hopefully rare events, e.g. not moving files and 2 multifile torrents have the same name. If downloading files are thus made readonly, the torrent is blocked at first write attempt, and you have to reset the readonly flag on the relevant files and start the blocked torrent. If you're having issues with single file torrents, you should simply remember to use a different command for these torrents, namely the same one without the star (%F* -> %F)

Is someone here proficient at writing windows scripts? I'm really no windows geek... I guess it should be quite easy to do.

what i'd like to have:

something to plug into the utorrent feature for a program to run after the torrent is finished, so that all files get marked as readonly

(+ hopefully there's a way to have this external call automatically set everytime I add a new torrent? I'm new to utorrent)

why I'd like to have that:

it's very easy to modify files mistakenly. I discovered today that the default vista jpg viewer modifies the file if I rotate the image to view it! So I guess I have some wrong data in some torrents I'm keeping (for seeding), since some came with images upside down or such. I was totally unaware of this. I hope at least some programs would refrain from silently modifying files if those files have the readonly attribute.

I'm trying to be cautious when I'm looking at my download folder, but it's a pain in the fingers. I'd like utorrent to be cautious for me.

I saw (search "readonly" -> thread from 2006/04) that there's been a feature request for that, but no such feature seems to have been implemented, so an external script would be a nice workaround. It's already easier to be cautious only when the forrent is not finished. (but i'd be of course nicer if every finished *file* got readonly)

Side questions:

- utorrent didn't complain. Is it that the few concerned pieces never get requested? Or is it that utorrent doesn't check last modified entry or such? I guess I might be seeding bad data. Am I correct?

- I guess marking files as readonly shouldn't have bad side effects? It seems copying files removes the readonly flag (I copy files out of the download folder before using them in the long run), so I guess everything should be ok.

thanks for any help! :)

Edit: as an afterthought, a "standalone" script that would mark as readonly every file of my download folder not ending with !ut would also do the trick

Link to comment
Share on other sites

For single-file .torrents:

cmd /c attrib +R "%D\%F"

For multi-file .torrents:

cmd /c attrib +R "%D\*" /S /D

"Hybrid" command:

cmd /c attrib +R "%D\%F*" /S /D

You should be able to use them in "Run Program" in the torrent properties' Advanced tab in µTorrent...



[li]Read-only for non-downloading files shouldn't be a problem for µTorrent[/li]

[li]This is absolutely untested with µTorrent -- I've only tried it only from Start > Run[/li]

[li]This won't handle the !ut case... That would probably be more involved than a simple one-liner[/li]

[li]No, running the script can't be set automatically, though the ability to do so has been requested before[/li]

[li]The command used for multi-file torrents may cause problems if you use it for single-file torrents in that files you might not want to be set as read-only will also get set to read-only if they share the same directory as the single file[/li]

[li]The hybrid behavior works because %F returns an empty string if you are dealing with a multi-file torrent (so it collapses to the same command as the multi-file command). For single-file torrents, the hybrid command should work well in most cases, but if you are downloading a file that is named foo.bar, and are downloading it to a directory containing files that start with the same name (like foo.bar1), those other files will get set to read-only as well.[/li]


Link to comment
Share on other sites

Uh, a minor correction... /k should actually be /c (otherwise, it'll open the command window and leave it open).

Another note: that line actually works properly only on multi-file torrents. On single file torrents, it might actually wreak a bit of unexpected havoc if you're downloading the single file to a directory with other files that you don't want set to read-only. The thing is, it actually sets all files in the directory and any subdirectories (recursive) to read-only. If you want to prevent that for single-file torrents, something like

cmd /c attrib +R "%D\%F"

would be more appropriate.

Then there's always another variation I thought of:

cmd /c attrib +R "%D\%F*" /S /D

This one I'd also be somewhat wary of, since it also might behave a bit unexpectedly on single-file torrents (though not as crazy as the previous one). %F returns the filename for a single-file torrent, but returns an empty string (nothing) for a multi-file torrent. So if you have a multi-file torrent, it won't behave any differently than the previous command (it'll simply collapse to "%D\*" since %F is empty). If you have a single-file torrent, though, it'll return something like "C:\hello world\abc.txt*" (which would set abc.txt to read-only). Now, if you don't have files that have the same beginning for their filenames, it'll be fine. What might cause unexpected behavior is if you have some file called abc.txt then abc.txt.jpg (or whatever), the later of which you don't want set to read-only.

The advantage to this last version is that you wouldn't have to remember whether you're trying to download a single-file or multi-file torrent. Take your pick :)

Link to comment
Share on other sites

ok so perhaps no so precise BUT with customer support :)

I'll actually leave the /k for the moment and see if I like to see some window advertising completion (+ I'll remember to check if it works and post here). I guess I'll go for /c for future torrents. (And yes I saw you also removed this weird @ from your first post :) )

so now waiting a few days for completion...

thanks again :)

Link to comment
Share on other sites

Heh, yeah, I removed the @ from the command. It didn't do all that much one way or another -- it simply meant not to print the attrib +R "%D\%F" part onto the command window when it is run ("silent," I suppose). If the window never stays open (because of /c), it's useless to have that extra character, since you wouldn't see anything anyway :P

Good luck (I hope it doesn't b0rk your computer up... I don't really consider it well-tested, simple a line as it may be xD).

Link to comment
Share on other sites

OK 2 torrents completed sooner than expected, so I can say:

yeah, it works fine!

(cmd /k attrib +R "%D\*" /S /D = multifile /k version)

I checked the default jpeg viewer won't alter readonly files (now the stupid thing wouldn't let me turn the images to *view* them, I definitely need to download some non-Microsoft thing)

good job!

I'll stick to /k I think, easy way to know how many torrents completed since last time I left the comp alone -- however, there's just a prompt in it, not the expanded command as I expected, is that your @ thing? -- that's fine anyway

Edit: I did a quick internet search, manual for cmd, they say ``

/k : Carries out the command specified by string and continues.

'' so I guess the window show only the "continues" part...

The good part is that I immediately ran into a gotcha of the thing: I had not paid attention to the fact that 2 of my torrents had the same name (1st time this happens to me...) -- so the 1st to complete blocked the 2d, because they downloaded to the same folder ;) funny coincidence

OK I'll test the more robust single/multiple version for the next completion (but I'm only downloading multi-files at the moment)

I hope they'll add the default after-script command for 1.8, as it's still a little tedious to paste the thing for every new torrent (I'm using a label when I've pasted it so I can quickly see if I forgot to do it)

but still a lot better imho than having to remember which folder I've already put readonly or not, I can safely use files directly in the download folder (I hope) before I've stored elsewhere. Great :)

Link to comment
Share on other sites

@jewelisheaven: seems you're trying to teach me how to search this forum ;) If you mean the idea that some settings could be automatically set when selecting a label, then yes, it would be more practical for me, just one action for each new torrent. 0 action would be even better... but well, I guess devs have more important priorities.

However, please consider that this whole thing is just a workaround with existing features to guard files agains unintended modification; what's missing imho is just a box to tick next to "append .!ut to incomplete files", namely "set readonly flag to completed files", which was requested before but didn't make it through even though it's easy quick code. The workaround can't do the work for completed files, only for completed torrents...

I edited my first post, trying to sum the thread up for the interested reader. Too bad there's no wiki.

Now, I'm trying to move files after completion of the torrent, so that I can have a secure folder with finished readonly files, and an "insecure" currently downloading torrents. I got an error with the 1st torrent completion, "unable to move, impossible to create an existing file". I had moved downloading torrents to a new location but first only paused them before realizing they needed to be stopped, it seems a failed hash happened just then and resulted in a file recreation in the original place somehow. ouch. try again :)

Link to comment
Share on other sites

yes it is: in the logger you see first the move, then the action performed with %D changed with the new folder. I downloaded a small torrent just to check this, and it works.

Good news :)

I edited my resume in my first post, I hope it's understandable and will be of use :)

Link to comment
Share on other sites

  • 1 year later...

Don't want to be pushy, but I guess settings like global/default/common/... run on completion script/executable path, custom additional trackers list, auto select/unselect, priority file pattern list, friend peers ip:port list, label picker by file wildcards...all can go into a new settings section in the future release?

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...