Editing Workspace Files (*.tws) directly

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
GenieMajik
Posts: 2
Joined: Thu Dec 11, 2003 2:48 am

Editing Workspace Files (*.tws) directly

Post by GenieMajik »

Hello all and thanks for reading...

I have a bunch of workspaces set up for my staging environment and was wondering if I could edit the workspace file directly and create workspaces for my production environment.

For example:
I have workspace D:\STG1.tws with files:
M:\something1\somethingElse1.txt
M:\something2\somethingElse1.txt
M:\something3\somethingElse1.txt
...

could I somehow copy and edit D:\STG1.tws to a D:\PROD1.tws and contain the files:
N:\something1\somethingElse1.txt
N:\something2\somethingElse1.txt
N:\something3\somethingElse1.txt
...

Can that be done?

Thanks for your help in advance. :D

GenieMajik
GenieMajik
Posts: 2
Joined: Thu Dec 11, 2003 2:48 am

Got it Nevermind

Post by GenieMajik »

I read through the forums for a solution but I couldn't find one directly but it was the first time I learned that the files in a workspace are relative to the workspace tws file

So...

I could open up an existing workspace, save it as a new workspace on the same drive as the files it contains and then move that new tws file to another drive. (if that makes sense).

Sorry for the crazy post :?

But thanks anyway :D
User avatar
CyberSlug
Posts: 120
Joined: Sat Oct 04, 2003 3:41 am

Post by CyberSlug »

Since TWS files have special meaning to TextPad, you can't use TextPad to edit them. You must use another text editor.

I saved two documents on my desktop plus a third in a subfolder, and I saved a workspace for them. I opened the worksapce file in Notepad:

Code: Select all

ÿÿ  TextPad         txt        ECOD
Document1.txt         TIDE  , , �Ù    0 VIEW                VIEW        VIEWð¥ZECOD
Document2.txt         TIDE  B B ÷à    0 VIEW                VIEW        VIEWð¥ZECODMyFolder\anotherFile.txt         TIDE  X X 
ö    0 VIEW                 VIEW        VIEWð¥Z
It seems you could change the names as long as you have the same number of files.
User avatar
MudGuard
Posts: 1295
Joined: Sun Mar 02, 2003 10:15 pm
Location: Munich, Germany
Contact:

Post by MudGuard »

Since TWS files have special meaning to TextPad, you can't use TextPad to edit them. You must use another text editor.
Not true.

Open Textpad.
File - Open, choose your tws file, switch File Format to "Text" and click "Open".

Up comes the content of the tws file in Textpad (lots of unreadable characters...)
User avatar
mishofsydenham
Posts: 3
Joined: Mon Feb 02, 2004 12:19 am

Post by mishofsydenham »

MudGuard wrote:(lots of unreadable characters...)
... which serves to show that persistence of workspaces should be implemented in XML! :D
joelmw
Posts: 20
Joined: Wed Mar 10, 2004 4:48 pm
Location: DFW
Contact:

Enhancement

Post by joelmw »

Does anyone know if this functionality--the ability to edit workspaces directly--has been entered as an enhancement request?

:?:

Thanks.
Grace and Peace,
Joel
mike777
Posts: 11
Joined: Mon Jun 23, 2003 3:01 pm

Post by mike777 »

I have the exact same issue.

I need to move a subfolder. In it, are 30 files in a TextPad Workspace. I don't want to have to reopen each one manually after I move the folder.

I'd like to be able to open the tws file, do a search and replace, and then find all my files in the new location.

I live and die by multiple (60 plus) workspaces which contain 30-50 files each, so this is very very important to my way of working.

I've tried bringing in the tws file in Notepad++ and replacing but it really messes up the tws file and I lose all my file references. Not good.

Someone, please find an answer to this. It's hard to believe this has been a request for so long without a resolution.
ben_josephs
Posts: 2457
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

This is not a perfect solution, but it's what I do.

If you use the command line and have Perl you can use something like the following script, which lists all the files in all the workspaces given as parameters (wildcards accepted).

Code: Select all

use warnings ;
use strict   ;

my @twsNames = map { glob $_ } ( @ARGV ? @ARGV : ( '*.tws' ) ) ;

for my $twsName ( @twsNames )
{
  if ( -f $twsName && $twsName =~ /\.tws$/ )
  {
    print "\n$twsName\n" ;

    if ( open TWS, $twsName )
    {
      local $/ = undef ;
      my $tws = <TWS> ;
      close TWS ;

      my @docNames = $tws =~ /[EB]COD..(.+?)\x00/gs ;

      for my $docName ( sort @docNames )
      {
        print "$docName\n" ;
      }
    }
    else
    {
      warn "Can't open $twsName.\n" ;
    }
  }
  elsif ( -f $twsName )
  {
    print "\n$twsName is not a workspace file.\n" ;
  }
  else
  {
    print "\n$twsName doesn't exist.\n" ;
  }
}
Thanks to lotus298 (see http://forums.textpad.com/viewtopic.php?t=8561) for some ideas in this.

If you redirect the output to a file, you can open it and edit the paths. You can then open each document quickly if you assign a keyboard shortcut (I use Ctrl+Shift+G) to the FileGoTo command:

Configure | Preferences | Keyboard:
Categories: File
Commands: FileGoTo
User avatar
woho
Posts: 100
Joined: Tue Sep 02, 2003 9:12 am
Location: Steyr/Austria
Contact:

Post by woho »

@mike777

A)
In it, are 30 files in a TextPad Workspace. I don't want to have to reopen each one manually ..
a) drag & drop from explorer to textpad is fine for opening many files in the same directory

b) Quick Open File (<Ctrl>+<Shift>+O, no menu entry for that !!) is very nice if the files are not in 1 single directory but in subdirectories on the same path ! You can use wildcards => see online help

c) if the filenames are always the same you could use also a filelist (textfile with name beginning with '@' =>search @ in the online help)

B)
not sure whether it is the same task or something different
As - as mentioned in the 2nd post of this thread - paths in *.tws are relative it works like that for me:
\myCurrProject
\mySubDir1
\mySubDir2
proj.tws .. containing files of \mySubDir*

when I copy
\myCurrProject to
\myCurrProjectBACKUP
and open
\myCurrProjectBACKUP\proj.tws
all the files in \mySubDir* are opened in \myCurrProjectBACKUP instead of \myCurrProject
ben_josephs
Posts: 2457
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

You can use an @-file, as suggested by woho in point (A)(c), in conjunction with something similar to my script. above. You'll need to remove this line:

Code: Select all

print "\n$twsName\n" ; 
Here's a fairly minimal version, without error checking:

Code: Select all

my $twsName = $ARGV[ 0 ] ;

open TWS, $twsName ;
my $tws = do { local $/ ; <TWS> } ;
close TWS ;

my @docNames = $tws =~ /[EB]COD..(.+?)\x00/gs ;

print +( join "\n", sort @docNames ), "\n" ;
which you can write even more minimally, like this

Code: Select all

print +( join "\n", sort do { open TWS, $ARGV[0] ; local $/ ; <TWS> } =~ /[EB]COD..(.+?)\x00/gs ), "\n" ;
if you like that sort of thing.

On woho's point (B): a file in a workspace is stored with a relative path only if it's in or below the directory containing the workspace.
BWMorlan
Posts: 2
Joined: Wed Aug 29, 2012 7:40 pm

Editing Workspace Files (*.tws) directly (in R)

Post by BWMorlan »

I use TWS all the time with my Sweave/R and routinely have 10-15 files open.

It would be very handy to be able to automatically read the TWS (I'll point to it) from R so I can add documentation on the files used in a project.

A simple scan() really messed up system, changing the character coding.

I am able to use
twsFile <- "/people/ccs3/morlan/research/bcp/bcp.tws"

if ( exists("con") ) close(con)
# con <- file(twsFile,"rb",encoding="UCS-2LE")
con <- file(twsFile,"rb")
str <- NULL
for ( ii in 1:1000 )
{
tried <- try(newC <- readChar(con,1))
if ( class(tried)!="try-error" ) str <- c(str,newC)
}

to load the tws one character at a time, but am not able to filter it very well. Has anyone written an R-function that might already do this?

I'll be writing one anyway, but if it is already out there that would be nice.
The Price of Freedom is eternal vigilance.

Eternal Vigilance is now on sale at WMart for $260B
BWMorlan
Posts: 2
Joined: Wed Aug 29, 2012 7:40 pm

R function to scan TWS files

Post by BWMorlan »

The following function reads in a TWS and attempts to parse it for the file names. It returns an unnamed list. It is easy to modify it, as written it expects file names to only contain letters and numbers and : to mark Windows drive letters.

Code: Select all

scan.twsFile <- function(twsFile="/people/ccs3/morlan/research/bcp/bcp.tws",type="latex")
{# PURPOSE: To read in a TextPad TWS file and produce a list of files
 # USE:  lst <- scan.twsFile(twsFile="<fullpath to twsfile>")

  if ( exists("con") ) close(con)
  con <- file(twsFile,"rb")
  str <- NULL
  fileSize <- file.info(twsFile)$size
  for ( ii in 1:fileSize )
  {
    tried <- try(newC <- readChar(con,1),silent=TRUE)
    if ( class(tried)!="try-error" ) str <- c(str,newC)
  }

  c0 <- str %in% c("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
                   "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
                   "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", 
                   ":", "\\",".")
  str <- str[c0]
  str <- gsub("\\\\","/",str)
  str <- paste(str,collapse="")

###
# hope the markers don't change
###
  keyStr0 <- "EC"
  keyStr1 <- "OD"
  c0 <- regexpr(keyStr0,str)
  editFiles <- NULL
  while (c0[1]>0)
  {
    str       <- substring(str,c0[1]+nchar(keyStr0))
    c0        <- regexpr(keyStr1,str)
    str       <- substring(str,c0[1]+nchar(keyStr1))
    keyStr0   <- "TIDEVIEW"
    keyStr1   <- "VIEWECOD"
    c1        <- regexpr(keyStr0,str)
    editFiles <- c(editFiles,substring(str,1,c1-1))
    str       <- substring(str,c1)
    c0        <- regexpr(keyStr0,str)
  }

  editFiles <- editFiles[editFiles!=""]
  c0 <- substring(editFiles,1,1)=="."
  editFiles[c0] <- substring(editFiles[c0],2)

  return(invisible(editFiles))
 # END FUNCTION scan.twsFile()  as  found in   source(paste(RCommon,"LatexTools/latex.twsFiles.R",sep=""))
}# END FUNCTION scan.twsFile()
The Price of Freedom is eternal vigilance.

Eternal Vigilance is now on sale at WMart for $260B
Post Reply