I use this code to upload text file to the folder. It works fine, file is in folder. File is named by multimedia id -"mid.txt"(i.e: "1.txt"):
Part of upload.php:
if(isset($_POST['btn-upload']))
{
$folder="/var/www/tmp/textgrid_uploads/$mid.txt";
I want to use the uploaded file "$mid.txt" from "textgrid_uploads" directory in script for conversion. The script "conversion.sh" has defined "input", "output" and "temporary" file because it has to be defined to store temp file:
Part of script "conversion.sh":
mid=$1
infile="/var/www/tmp/textgrid_uploads/$mid"
outfile="/var/www/tmp/mlf/${mid}.mlf"
tmpfile="/var/www/tmp/mlf/${mid}.tmp"
The script works fine, becasuse I tested it for files which were created manually on server using: vim 1.txt. Problem is when I want to use script "conversion.sh" for file which was uploaded on server using "upload.php". After using script "conversion.sh" It creates blank file called "$mid.mlf" in "mlf" directory with no text. Running of "conversion.sh": i.e: ./conversion.sh 1.txt
Related
I'll start by mentioning that I've no knowledge in Python but read online that it could help me with my situation.
I'd like to do a few things using (I believe?) a Python script.
I have a bunch of .yml files that I want to transfer the contents into one main .yml file (let's call it Main.yml). However, I'd also like to be able to take the name of each individual .yml and add it before it's content into Main.yml as "##Name". If possible, the script would look like each file in a directory, instead of having to list every .yml file I want it to look for (my directory in question only contains .yml files). Not sure if I need to specify, but just in case: I want to append the contents of all files into Main.yml & keep the indentation (spacing). P.S. I'm on Windows
Example of what I want:
File: Apes.yml
Contents:
Documentation:
"Apes":
year: 2009
img: 'link'
After running the script, my Main.yml would like like:
##Apes.yml
Documentation:
"Apes":
year: 2009
img: 'link'
I'm just starting out in Python too so this was a great opportunity to see if my newly learned skills work!
I think you want to use the os.walk function to go through all of the files and folders in the directory.
This code should work - it assumes your files are stored in a folder called "Folder" which is a subfolder of where your Python script is stored
# This ensures that you have the correct library available
import os
# Open a new file to write to
output_file = open('output.txt','w+')
# This starts the 'walk' through the directory
for folder , sub_folders , files in os.walk("Folder"):
# For each file...
for f in files:
# create the current path using the folder variable plus the file variable
current_path = folder+"\\"+f
# write the filename & path to the current open file
output_file.write(current_path)
# Open the file to read the contents
current_file = open(current_path, 'r')
# read each line one at a time and then write them to your file
for line in current_file:
output_file.write(line)
# close the file
current_file.close()
#close your output file
output_file.close()
I am opening some VTU files from Directory X and there are other output files in that directory (for example log.txt) that I want to open via a plugin. If I do a os.getcwd() I end up in ParaViews installation directory. What I want is the directory of the VTU files I loaded BEFORE applying the plugin... So basically the start Point of the Pipline.
You could do something like this to get the reader
myreader = FindSource('MyReader')
then get the file name via the FileName attribute
myreader.FileName
I wrote a php script to get my latest Twitter tweet and save it to a file. Here is the part doing so :
// No errors exist. Write tweets to json/txt file.
$file = $twitteruser."-tweets.txt";
$fh = fopen($file, 'w') or die("can't open file");
fwrite($fh, json_encode($tweets));
fclose($fh);
This works fine when I run my php script directly in the browser, however, when I run the file from a cron job it creates the file in my user root directory (obviously not the correct place).
If I change the above line to :
$file = "public_html/get-tweets/".$twitteruser."-tweets.txt";
the cronjob now works and saves to the correct location, but then manually running the file in my browser gives an fopen error that the file does not exist.
What the heck is the problem? I need this to work both from cronjob and manually.
Use a full path from the root of the filesystem, then both should be fine.
I have the script that creates some .html and .txt files every day. But now it is only one file html and txt with changed content, I need every day a new html&txt file with date oof creation in the file name like : index_22-05-2013.html , i have these variables in shell script:
DESTINATION_HTML="./daily/html/index_$(date +"%F").html"
DESTINATION_TXT="./daily/txt/index_$(date +"%F").txt"
and a line in shell script that running one python script and creates html file
python `somescript.py` -m ${FILELIST[0]} ${FILELIST[1]} > $DESTINATION_HTML
and i`m getting this file created:
index_$(date +"%F").html
what i must to do to get this file name : index_22-05-2013.html
Sorry, I am not following you, but since
echo "index_$(date +%F).html"
outputs index_2013-08-20.html instead of index_22-05-2013.html which is what you need, you probably want to use this command instead:
echo "index_$(date +%d-%m-%Y).html"
Hope it helps! :)
I'm using ImageMagick to do some image processing from the commandline, and would like to operate on a list of files as specified in foo.txt. From the instructions here: http://www.imagemagick.org/script/command-line-processing.php I see that I can use Filename References from a file prefixed with #. When I run something like:
montage #foo.txt output.jpg
everything works as expected, as long as foo.txt is in the current directory. However, when I try to access bar.txt in a different directory by running:
montage /some_directory/#bar.txt
output2.jpg
I get:
montage: unable to open image
/some_directory/#bar.txt: No such file
or directory # blob.c/OpenBlob/2480.
I believe the issue is my syntax, but I'm not sure what to change it to. Any help would be appreciated.
Quite an old entry but it seems relatively obvious that you need to put the # before the full path:
montage #/some_directory/bar.txt output2.jpg
As of ImageMagick 6.5.4-7 2014-02-10, paths are not supported with # syntax. The # file must be in the current directory and identified by name only.
I haven't tried directing IM to pull the list of files from a file, but I do specify multiple files on the command line like this:
gm -sOutputFile=dest.ext -f file1.ppm file2.ppm file3.ppm
Can you pull the contents of that file into a variable, and then let the shell expand that variable?