Selection from text file!

Can i select fiiles & folder whose paths exists in text file!
contents of text file (for ex)
C:\Documents and Settings\All Users\NTUSER.DAT
C:\Documents and Settings\All Users\Application Data\GPSoftware\Directory Opus
C:\Documents and Settings\All Users\Application Data\Adobe\Acrobat
I want to select all this files & dirs! may I?

I'm not sure why you would want to do this, but nevertheless, here's the way I'd go about it.

First create your text file which will only contain the names of the files and folders to be selected. The files and folders must have their fully qualified names as you show in your example. In my example here that text file is named C:\temp\Temp.txt

Next create another new text file and paste the following into it:

[code]@echo off
set F=C:\temp\Temp.txt

for /f "tokens=*" %%a in ('type "%F%"') do (
dopusrt /cmd Go "%%~dpa" NEWTAB FINDEXISTING
dopusrt /cmd Select "%%~nxa"
)[/code]

You will need change the line that starts with set F= to be the text file you have with the fully qualified file names to be selected.

Save that file giving it a name that ends in .CMD which makes it a batch file. In my example the batch file is named D:\Mine\cmd\Test.cmd

Then in Opus, create a button that looks something like the screen grab below. In my example, I just left everything named "test" you would want to use more descriptive names of course. When you push the button, each file should get selected in a new tab unless two or more files are in the same folder.

Hi John,

Thanks for the short tutorial on using dopusrt...

An alternative possibility would be to copy all the files into a new collection and select the whole new collection. That has to be possible in Opus, just not sure how to go about it... But looking at your code, that should not be too difficult, right? The advantage being you're not creating a whole set of new tabs and you've got all the files & folders selected at once.

Something like this?

@echo off
set F=C:\temp\temp.txt

dopusrt /cmd Go coll://
dopusrt /cmd CreateFolder Temp
dopusrt /cmd Go coll://Temp

for /f "tokens=*" %%a in ('type "%F%"') do (
  dopusrt /cmd Copy FILE "%%a" TO="coll://Temp" COPYTOCOLL=member
)
dopusrt /cmd Select ALL

You would need to do something to make sure you create a new collection, remove the collection manually after you're done, etc...

If anyone feels like extending this, be my guest. :slight_smile:

Hope this helps the OP.

Regards,
Marcel

You can simplify it a bit, both the "for" line and the collection-creation stuff:

@echo off for /f %%a in (C:\temp\temp.txt) do ( dopusrt /cmd Copy FILE="%%a" TO="coll://" CREATEFOLDER="Temp" COPYTOCOLL=member ) dopusrt /cmd Go coll://Temp dopusrt /cmd Select ALL

(I had to replace all the "dopusrt" with the full, quoted path to dopusrt.exe, since this is being run as an external batch file and dopusrt.exe isn't in the default path. I've left the example above as-is to keep things short & simple.)

You could extend this a bit so that the list-file path is given to the batch file as an argument. You could then make an Opus button which calls the batch file, passing {filepath$} as the argument. That would let you select a list file and then click a button in Opus to select its contents.

(I experimented with making the whole thing work inside of an Opus button but there's something strange going on with the quotes and/or % codes which I don't have time to look at. It's weird since I checked the .bat file which Opus generates and it's identical to the one I am running by hand, except for the chcp line that Opus adds, which shouldn't be relevant. Ah, the joys of the MS-DOS parser!)

Hi Leo

Good stuff. I knew there had to be an easier way. And who else to point us in the direction... :wink:

I probably didn't have a problem with that since I temporarily dumped the batch file in the same directory...

[quote="leo"]You could extend this a bit so that the list-file path is given to the batch file as an argument. You could then make an Opus button which calls the batch file, passing {filepath$} as the argument. That would let you select a list file and then click a button in Opus to select its contents.
[/quote]

Yeah, I was thinking along those same lines. You could define a new filetype and add context menu entries for it ("Select by list file", "Delete by list file", etc etc).

Excuse me? :open_mouth: You mean there's even more I don't know?? :wink:

Excuse me? :open_mouth: You mean there's even more I don't know?? :wink:[/quote]
If you make a button with the MS-DOS Batch type then Opus will generate and run temporary .bat files when you click on it.

(If all of the commands are external then there will just be one .bat file, with any {filepath}-type arguments filled in. If, instead, the button mixes internal and external commands then there may be several batch files, one for each uninterrupted sequence of external commands. That's one reason why it's a bad idea to use internal commands in an MS-DOS Batch button that has looping or conditional logic, since the batch file may be split up and break all of that.)

If you go to /temp and look for the dop*.tmp files (I think that's the name of them) then you'll find the temporary batch files. Opus cleans them up a little while after the button stops running. (If you have trouble finding the batch files they may have already been cleaned up. Add a Pause command to the end of the button and the temp batch file should stay around longer, I think.)

leo's button doesn't works with spaces, but mvdlaan's button works fine! why?

what is "tokens=*"?

how do i use add-switch with copynames option? is it possible?
i want to copy filenames from differnt locations?

clipboard copynames add!!!

It's one of many bugs in the Windows CMD scripting language. That's why my original script, and Marcel's (mvdlaan), used the type command to avoid that little problem with spaces in file names.

Tokens are a part of the FOR iteration command in the Windows CMD scripting language. You use them to parse only certain parts of what you're working with. In this case where we were parsing individual lines in a text file, tokens=* tells the FOR iterator command to parse each entire line in the text file. On the other hand if we only wanted to parse the first word of each line in that text file we would have used tokens=1. Tokens are used in conjunction with the delims argument which sets the delimiters the FOR command uses, which by default are spaces.

[quote="fkast"]how do i use add-switch with copynames option? is it possible?
i want to copy filenames from differnt locations?

clipboard copynames add!!![/quote]

I'm afraid I don't understand what you're asking us.

It's one of many bugs in the Windows CMD scripting language. That's why my original script, and Marcel's (mvdlaan), used the type command to avoid that little problem with spaces in file names.[/quote]

Ah, I wondered why the original was like that. That may explain why I had problems running the same script within an Opus button, too.

Strange, though, as I tested it with at least one filepath containing a space and it worked fine, so long as the batch was in a separate .bat file and not an Opus command. Or at least it seemed to. It's like only certain paths trigger the problem or it matters where the .bat file was saved to. Quite strange.

Heh, Every time I mess with DOS batch files I try to remember to never touch them again due to all the quirks and broken stuff making what should be simple take so long to work out. My button to cycle through a list of paths started off as a DOS batch file but after an hour of trying to get either a for-loop which iterates over some literal string tokens, or a nested for-loop, I gave up and started again using VBScript, which was straightforward. :slight_smile:

I hear ya on that Leo. CMD is chock full of bugs, Microsoft couldn't even get the basic echo command to work right under all conditions. I only keep up on CMD scripting to help others, myself I use 4NT instead.

[quote="JohnZeman"]... CMD is chock full of bugs, Microsoft couldn't even get the basic echo command to work right under all conditions. I only keep up on CMD scripting to help others, myself I use 4NT instead.[/quote]... and for those who want to follow your example, there is now a free version called TCC LE at: jpsoft.com/tccledes.htm.