Open files listed in txt - r

I have a list of files with their full path in a single text file. I would like to open them all at once in Windows. The file extension will tell Windows what programme to use. Can I do this straight from the command line or would I need to make a batch file? Tips on how to write the batch file appreciated.
My text file looks like the following:
J:/630/630A/SZ299_2013-04-19_19_36_52_M01240.WAV
J:/630/630A/SZ299_2013-04-19_20_15_39_M02312.WAV
J:/630/630A/SZ299_2013-04-19_21_48_07_M04876.WAV
etc
The .WAV extension is associated with Adobe Audition, which is a sound editing programme. When each path is hyperlinked in an Excel column, they can be opened with one click. Clicking on the first link will open both Audition and the hyperlinked file in it. Clicking another hyperlink will open the next file in the same instance of the programme. But this is too slow for hundreds of paths. If I open many files straight from R, e.g.
shell("J:/630/630A/SZ299_2013-04-19_19_36_52_M01240.WAV", intern=TRUE)
shell("J:/630/630A/SZ299_2013-04-19_20_15_39_M02312.WAV", intern=TRUE)
etc
each file will be opened in a new instance of the programme, which is nasty. So batch seems preferable.

for /f "delims=" %%a in (yourtextflename) do "%%a"
should do this as a batch line.
You could run this directly from the prompt if you like, but you'd need to replace each %% with % to do so.
It's a lot easier to put the code into a batch:
#echo off
setlocal
for /f "delims=" %%a in (%1) do "%%a"
then you'd just need to enter
thisbatchfilename yourtextfilename
and yourtextfilename will be substituted for %1. MUSCH easier to type - and that's what batch is all about - repetitive tasks.

Following on from this post, which uses the identify function in R to create a subset selection of rows (from a larger dataset called "testfile") by clicking on coordinates in a scatterplot. One of the columns contains the list of Windows paths to original acoustic datafiles. The last line below will open all files in the listed paths in only one instance of the programme linked to the Windows file extension.
selected_rows = with(testfile, identify(xvalue, yvalue))
SEL <-testfile[selected_rows,]
for (f in 1:nrow(SEL)){system2("open",toString(SEL[f,]$path))}

Related

How to add new text to file names while being input into a text file in unix

Hopefully this is straightforward, but I'm trying to somewhat automate the creation of a manifest file for Qiime. I have a few hundred .fastq files that I want to read into a .txt file with a filepath attached.
For example, the file names are SRR201691_1.fastq and I want them to be moved to a .txt file but now contain /file/path/SRR201691_1.fastq. I have the code below that moves the names...
ls *1.fastq >> forward-manifest.txt
Thank you
Something like
printf "/file/path/%s\n" *1.fastq >> forward-manifest.txt
should do it.

tail -f did not continue output the new lines added using vi

When I invoked "tail -f myfile.txt", the new line added using the following command output the new line, but not the line added/saved using vi. Does anyone know why ?
$echo "this is new line" >> myfile.txt
Thanks.
It has something to do w/the fact that while you are editing the file, vi keeps your changes in a second file (.myfile.txt.swp in this case).
When you save the changes, it's likely that vi is replacing the original file w/the second file. This means the file that tail was watching is no longer valid.
To prove this, try your echo command after saving the file with vi. When you do that, the output won't be displayed by tail.
The tail program opens a file, seeks to the end, and (with "-f") waits, then checks again if that open file has anything new to read.
vi does not append to a file. It makes a copy, (not a "swap", which is something else altogether) writes it out, and then moves the new file to have the same name as the old file.
tail is still watching the old file, not looking up a file by that file name every time.
In addition, tail uses the location in the file, so if you delete 10 characters and add 15, the next loop of 'tail' will emit the next 5 it thinks are new because they are after its placeholder.
Run 'tail --follow=name ...' to get tail to look up the file every loop by name, instead of watching the location on disk of a file it opens at start.

Pentaho unzip file

I have a zip folder and with two files, a.txt and b.txt, I want to bring only a.txt file, I'm using "Unzip file" step in pentaho. when I fill field "include wild card" the process don't bring any file, when I don't fill this field, the process bring all files. someboby can help me?
The "Wild Card" expression will work on the file list and not on the content of the file. For e.g. As in your case, if you are having a.txt and b.txt in a zip folder named : data.zip ; using "wild card expression" in the "Unzip file" step, it will only search for pattern in the "data.zip" folder and not inside the content of data.zip. This is the reason why your code was not unzipping when you included the regular expression, since you were trying to read "a.txt" instead of searching for data.zip.
As per your case, you can try a work around !! Try unzipping the content of the data.zip into an archieve folder (or anything similar) and then using the regular expression to read only the "a.txt" file from the archieve folder; instead of trying the first step.
Hope this might work out :)

Check if a file is open using Windows command line within R

I am using the shell() command to generate pdf documents from .tex files within a function. This function sometimes gets ran multiple times with adjusted data and so will overwrite the documents. Of course, if the pdf file is open when the .tex file is ran, it generates an error saying it can't run the .tex file. So I want to know whether there are any R or Windows cmd commands which will check whether a file is open or not?
I'm not claiming this as a great solution: it is hacky but maybe it will do. You can make a copy of the file and try to overwrite your original file with it. If it fails, no harm is made. If it succeeds, you'll have modified the file's info (not the contents) but since your end goal is to overwrite it anyway I doubt it will be a huge problem. In either case, you'll be fixed about whether or not the file can be rewritten.
is.writeable <- function(f) {
tmp <- tempfile()
file.copy(f, tmp)
success <- file.copy(tmp, f)
return(success)
}
openfiles /query /v|(findstr /i /c:"C:\Users\David Candy\Documents\Super.xls"&&echo File is open||echo File isn't opened)
Output
592 David Candy 1756 EXCEL.EXE C:\Users\David Candy\Documents\Super.xls
File is open
Findstr returns 0 if found and 1+ if not found or error.
& seperates commands on a line.
&& executes this command only if previous command's errorlevel is 0.
|| (not used above) executes this command only if previous command's errorlevel is NOT 0
> output to a file
>> append output to a file
< input from a file
| output of one command into the input of another command
^ escapes any of the above, including itself, if needed to be passed to a program
" parameters with spaces must be enclosed in quotes
+ used with copy to concatinate files. E.G. copy file1+file2 newfile
, used with copy to indicate missing parameters. This updates the files modified date. E.G. copy /b file1,,
%variablename% a inbuilt or user set environmental variable
!variablename! a user set environmental variable expanded at execution time, turned with SelLocal EnableDelayedExpansion command
%<number> (%1) the nth command line parameter passed to a batch file. %0 is the batchfile's name.
%* (%*) the entire command line.
%<a letter> or %%<a letter> (%A or %%A) the variable in a for loop. Single % sign at command prompt and double % sign in a batch file.
.
--

Which file contains asterisk in unix

All
Here i post my doubt about files with asterisk, First i create one file
touch test*
If i check ls -lrt it shows the test* file in the current.
Then i removed that file using rm *.
Then i create two files which are test1* test2* using same touch command.
If i check ls -lrt.
It displays the two files that are test1* and test2*.
Again i create test* using touch command , now i check ls -lrt.
This time it will not display the file test*.
Why the test* file is not listed ?
Thanks & regards
As * is used by your shell as universal character, when you write
touch test*
your shell will tranform it into
touch test1* test2*
If you want to create 'test*', use simple quote, which inhibit the globing function.
touch 'test*'
Normally touch command is used to create a empty file.
if file is already there it will change only the access time.
first time you are using the touch test*
that there is no test file so it will creates file names as test*
second time you are using touch test* that, time the current directory having test1* and test2* files,
so it will expand into test1* and test2* .
In that case it will change only the access time of the both file.
if you want to create one more time test* file means you can use double quotes.

Resources