[Bash] Massively replace text in all files of a directory

Hi everybody,
I wrote this small recursive function in order to massively replace some strings contained in all files of a directory (and all subdirectories). Any suggestions?
replaceText() {
# set the temporary location
local tFile="/tmp/out.tmp.$$"
# call variables
local script="$2"
local opts="${@:3}"
browse() {
for iFile in "$1"/*; do
if [ -d "$iFile" ];then
# enter subdirectory...
browse "$iFile"
elif [ -f $iFile -a -r $iFile ]; then
echo "$iFile"
sed $opts "s/$(echo $script)/g" "$iFile" > $tFile && mv $tFile "$iFile"
else
echo "Skip $iFile"
fi
done
browse $1
Syntax:
replaceText [path] [script] [sed options (optional)]
For example (it will replace "hello" with "hi" in all files):
replaceText /home/user/mydir hello/hi
Note: It is case-sensitive.
Bye,
grufo
Last edited by grufo (2012-11-10 15:05:43)

falconindy wrote:
Yes, find is recursive and extremely good at its job.
http://mywiki.wooledge.org/UsingFind
Well
falconindy wrote:Your lack of quoting is dangerous, as is your code injection in sed. I'm not sure why you're echoing a var inside a command substitution inside a sed expression, but it's going to be subject to word splitting, all forms of expansion, and may very well break the sed expression entirely, leading to bad things. A contrived example, but passing something like 'foo//;d;s/bar/' should effectively delete the contents of every file the function touches.
So, if you consider it dangerous, you can adopt the whole "sed syntax" and confirm before continue...:
replaceText() {
# set the temporary location
local tFile="/tmp/out.tmp.$$"
# call variables
local sedArgs="${@:2}"
browse() {
for iFile in "$1"/*; do
if [ -d "$iFile" ];then
# enter subdirectory...
browse "$iFile"
elif [ -f $iFile -a -r $iFile ]; then
echo "$iFile"
sed $sedArgs "$iFile" > $tFile && mv $tFile "$iFile"
else
echo "Skip $iFile"
fi
done
while true; do
read -p "Do you want to apply \"sed $sedArgs\" to all files contained in the directory $1? [y/n] " yn
case $yn in
[Yy]* ) browse $1; break;;
* ) exit;;
esac
done
Syntax:
replaceText [parent directory] [sed arguments]
Example:
replaceText /your/path -r 's/OldText/NewText/g'
or, if you want to work directly with the current directory...
replaceText() {
# set the temporary location
local tFile="/tmp/out.tmp.$$"
# call variables
local sedArgs="$@"
browse() {
for iFile in "$1"/*; do
if [ -d "$iFile" ];then
# enter subdirectory...
browse "$iFile"
elif [ -f $iFile -a -r $iFile ]; then
echo "$iFile"
sed $sedArgs "$iFile" > $tFile && mv $tFile "$iFile"
else
echo "Skip $iFile"
fi
done
while true; do
read -p "Do you want to apply \"sed $sedArgs\" to all files contained in the directory $PWD? [y/n] " yn
case $yn in
[Yy]* ) browse $PWD; break;;
* ) exit;;
esac
done
Syntax:
replaceText [sed arguments]
Example:
replaceText -r 's/OldText/NewText/g'
What about?
falconindy wrote:I'll also point out that declaring a function within a function doesn't provide any amount of scoping -- 'browse' will be declared in the user's namespace after running this function for the first time.
See:
function1() {
function2() {
echo "Ciao"
function2
function2 # error
function1 # works

Similar Messages

  • How to get the file size (in bytes) for all files in a directory?

    How to get the file size (in bytes) for all files in a directory?
    The following code does not work. isFile() does NOT recognize files as files but only as directories. Why?
    Furthermore the size is not retrieved correctly.
    How do I have to code it otherwise? Is there a way of not converting f-to-string-to-File again but iterate over all file objects instead?
    Thank you
    Peter
    java.io.File f = new java.io.File("D:/todo/");
    files = f.list();
    for (int i = 0; i < files.length; i++) {
    System.out.println("fn=" + files);
    if (new File(files[i]).isFile())
         System.out.println("file[" + i + "]=" + files[i] + " size=" + (new File(files[i])).length() ); }

    pstein wrote:
    ...The following code does not work. Work?! It does not even compile! Please consider posting code in the form of an SSCCE in future.
    Here is an SSCCE.
    import java.io.File;
    class ListFiles {
        public static void main(String[] args) {
            java.io.File f = new java.io.File("/media/disk");
            // provides only the file names, not the path/name!
            //String[] files = f.list();
            File[] files = f.listFiles();
            for (int i = 0; i < files.length; i++) {
                System.out.println("fn=" + files);
    if (files[i].isFile()) {
    System.out.println(
    "file[" +
    i +
    "]=" +
    files[i] +
    " size=" +
    (files[i]).length() );
    }Edit 1:
    Also, in future, when posting code, code snippets, HTML/XML or input/output, please use the code tags to retain the indentation and formatting.   To do that, select the code and click the CODE button seen on the Plain Text tab of the message posting form.  It took me longer to clean up that code and turn it into an SSCCE, than it took to +solve the problem.+
    Edited by: AndrewThompson64 on Jul 21, 2009 8:47 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Load all files in a directory

    hi all! im new to java and i was wondering if u can help me out!
    ive wrote a small application which analysises words in a text file, and what i need to do is load all the files in a directory, rather than one at a time like in the following code. I understand that a loop is needed but i really dont know where to start! please help!
    thanks for your time
    oh also, is there a way of the system printing the filename rather than "this text is.."?
    import java.io.BufferedReader;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.io.IOException;
    import java.util.HashMap;
    public class eval {
    private String[] words;
    private int[] values;
    private int num;
    private HashMap <String, Integer> hashMap;
    private arrays a;
    private String[] negwords;
    private int[] negvalues;
    private HashMap hashMap2;
    private int negnum;
    public eval() {
    initiatemap();
    BufferedReader in = null;
    try {
    in = new BufferedReader (new FileReader ("text.txt")); //id like this to load all files in a directory
    String str;
    String s;
    while ((str = in.readLine()) != null)
    str = str.replaceAll("[\\p{Punct}&&[^?????????????????????]]", " ");
    String[]temp = str.split(" ");
    for (int i = 0; i < temp.length; i++) {
    if (hashMap.containsKey(temp)) {
    num++;
    for (int i = 0; i < temp.length; i++) {
    if (hashMap2.containsKey(temp[i])) {
    negnum++;
    if (num > 0 && negnum > 0 ){
    double total = num + negnum;
    double txt1 = round((num/total)*100, 2);
    if (txt1 < 50)
    System.out.println("This text is " + txt1 + "% positive and is therefore not a happy text.");
    else if (txt1 >= 50 && txt1 <=65)
    System.out.println("This text is " + txt1 + "% positive, but does contain " + (100 - txt1) + "% negative words, it is therefore probably not a happy text.");
    else if (txt1 > 65)
    System.out.println("This text is " + txt1 + "% positive, and is therefore a happy text.");
    in.close();
    catch (FileNotFoundException e) {
    e.printStackTrace();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    public static double round(double val, int places) {
    long factor = (long)Math.pow(10,places);
    // Shift the decimal the correct number of places
    // to the right.
    val = val * factor;
    // Round to the nearest integer.
    long tmp = Math.round(val);
    // Shift the decimal the correct number of places
    // back to the left.
    return (double)tmp / factor;
    public void initiatemap()
    a = new arrays();
    words = a.initiateWords();
    negwords = a.initiateNegWords();
    values = a.initiateValues();
    negvalues = a.initiateNegValues();
    hashMap = a.initiateMap();
    hashMap2 = a.initiateNegMap();
    for (int i = 0; i < words.length; i++) {
    hashMap.put(words[i], values[i]);}
    for (int j = 0; j < negwords.length; j++) {
    hashMap2.put(negwords[j], negvalues[j]);}
    public static void main(String[] args) {
    eval eval = new eval();

    hi again,
    ok thanks for the help, ive have made the changes and i am now getting results.. however the results aren't correct!
    if i load the texts in one at a time, i get entirely different results to what is being printed. any suggestions?
    thanks again, i really really appreciate your help
    Torre
    private static void readMultipleFilesFromADirectory()
    File directory = new File(multipleFilesDirectory);
    // just to double check that this is a directory
    if (directory.isDirectory())
    File[] allFilesWithinThisDirectory = directory.listFiles();
    BufferedReader in = null;
    for (File file: allFilesWithinThisDirectory)
    initiatemap();
    try {
    in = new BufferedReader (new FileReader (file));
    String str;
    String s;
    while ((str = in.readLine()) != null)
    str = str.replaceAll("[
    p{Punct}&&--^&aacute;&acirc;&atilde;&auml;&eacute;&ecirc;&euml;&igrave;&iacute;&icirc;&iuml;&ograve;&oacute;&ocirc;&ouml;&ugrave;&uacute;&ucirc;&uuml;&ccedil;&egrave;]--", " ");
    String[]temp = str.split(" ");
    for (int i = 0; i < temp.length; i++) {
    if (hashMap.containsKey(temp)) {
    num++;
    for (int i = 0; i < temp.length; i++) {
    if (hashMap2.containsKey(temp[i])) {
    negnum++;
    if (num > 0 && negnum > 0 ){
    double total = num + negnum;
    double txt1 = round((num/total)*100, 2);
    if (txt1 < 50)
    System.out.println(file + " is " + txt1 + "% positive and is therefore not a happy text.");
    else if (txt1 >= 50 && txt1 <=65)
    System.out.println(file +" is " + txt1 + "% positive, but does contain " + (100 - txt1) + "% negative words, it is therefore probably not a happy text.");
    else if (txt1 > 65)
    System.out.println(file +" is " + txt1 + "% positive, and is therefore a happy text.");
    in.close();
    catch (FileNotFoundException e) {
    e.printStackTrace();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    results:
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv416_11136.txt is 60.65% positive, but does contain 39.35% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv417_13115.txt is 60.66% positive, but does contain 39.34% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv418_14774.txt is 60.68% positive, but does contain 39.32% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv419_13394.txt is 60.69% positive, but does contain 39.31% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv420_28795.txt is 60.66% positive, but does contain 39.34% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv421_9709.txt is 60.65% positive, but does contain 39.35% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv422_9381.txt is 60.69% positive, but does contain 39.31% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv423_11155.txt is 60.69% positive, but does contain 39.31% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv424_8831.txt is 60.67% positive, but does contain 39.33% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv425_8250.txt is 60.67% positive, but does contain 39.33% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv426_10421.txt is 60.69% positive, but does contain 39.31% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv427_10825.txt is 60.66% positive, but does contain 39.34% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv428_11347.txt is 60.68% positive, but does contain 39.32% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv429_7439.txt is 60.69% positive, but does contain 39.31% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv430_17351.txt is 60.68% positive, but does contain 39.32% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv431_7085.txt is 60.67% positive, but does contain 39.33% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv432_14224.txt is 60.67% positive, but does contain 39.33% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv433_10144.txt is 60.66% positive, but does contain 39.34% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv434_5793.txt is 60.63% positive, but does contain 39.37% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv435_23110.txt is 60.62% positive, but does contain 39.38% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv436_19179.txt is 60.68% positive, but does contain 39.32% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv437_22849.txt is 60.69% positive, but does contain 39.31% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv438_8043.txt is 60.65% positive, but does contain 39.35% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv439_15970.txt is 60.68% positive, but does contain 39.32% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv440_15243.txt is 60.66% positive, but does contain 39.34% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv441_13711.txt is 60.64% positive, but does contain 39.36% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv442_13846.txt is 60.61% positive, but does contain 39.39% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv443_21118.txt is 60.61% positive, but does contain 39.39% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv444_9974.txt is 60.6% positive, but does contain 39.4% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv445_25882.txt is 60.56% positive, but does contain 39.44% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv446_11353.txt is 60.54% positive, but does contain 39.46% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv447_27332.txt is 60.54% positive, but does contain 39.46% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv448_14695.txt is 60.56% positive, but does contain 39.44% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv449_8785.txt is 60.55% positive, but does contain 39.45% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv450_7890.txt is 60.54% positive, but does contain 39.46% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv451_10690.txt is 60.54% positive, but does contain 39.46% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv452_5088.txt is 60.53% positive, but does contain 39.47% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv453_10379.txt is 60.56% positive, but does contain 39.44% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv454_2053.txt is 60.55% positive, but does contain 39.45% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv455_29000.txt is 60.55% positive, but does contain 39.45% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv456_18985.txt is 60.57% positive, but does contain 39.43% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv457_18453.txt is 60.53% positive, but does contain 39.47% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv458_8604.txt is 60.53% positive, but does contain 39.47% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv459_20319.txt is 60.5% positive, but does contain 39.5% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv460_10842.txt is 60.54% positive, but does contain 39.46% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv461_19600.txt is 60.48% positive, but does contain 39.52% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv462_19350.txt is 60.47% positive, but does contain 39.53% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv463_10343.txt is 60.49% positive, but does contain 39.51% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv464_15650.txt is 60.48% positive, but does contain 39.52% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv465_22431.txt is 60.46% positive, but does contain 39.54% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv466_18722.txt is 60.46% positive, but does contain 39.54% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv467_25773.txt is 60.45% positive, but does contain 39.55% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv468_15228.txt is 60.47% positive, but does contain 39.53% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv469_20630.txt is 60.42% positive, but does contain 39.58% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv470_15952.txt is 60.39% positive, but does contain 39.61% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv471_16858.txt is 60.4% positive, but does contain 39.6% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv472_29280.txt is 60.4% positive, but does contain 39.6% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv473_7367.txt is 60.38% positive, but does contain 39.62% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv474_10209.txt is 60.38% positive, but does contain 39.62% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv475_21692.txt is 60.42% positive, but does contain 39.58% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv476_16856.txt is 60.43% positive, but does contain 39.57% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv477_22479.txt is 60.48% positive, but does contain 39.52% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv478_14309.txt is 60.47% positive, but does contain 39.53% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv479_5649.txt is 60.44% positive, but does contain 39.56% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv480_19817.txt is 60.45% positive, but does contain 39.55% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv481_7436.txt is 60.43% positive, but does contain 39.57% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv482_10580.txt is 60.43% positive, but does contain 39.57% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv483_16378.txt is 60.44% positive, but does contain 39.56% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv484_25054.txt is 60.43% positive, but does contain 39.57% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv485_26649.txt is 60.45% positive, but does contain 39.55% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv486_9799.txt is 60.44% positive, but does contain 39.56% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv487_10446.txt is 60.42% positive, but does contain 39.58% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv488_19856.txt is 60.41% positive, but does contain 39.59% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv489_17906.txt is 60.4% positive, but does contain 39.6% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv490_17872.txt is 60.42% positive, but does contain 39.58% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv491_12145.txt is 60.44% positive, but does contain 39.56% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv492_18271.txt is 60.44% positive, but does contain 39.56% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv493_12839.txt is 60.43% positive, but does contain 39.57% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv494_17389.txt is 60.43% positive, but does contain 39.57% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv495_14518.txt is 60.41% positive, but does contain 39.59% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv496_10530.txt is 60.39% positive, but does contain 39.61% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv497_26980.txt is 60.39% positive, but does contain 39.61% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv498_8832.txt is 60.38% positive, but does contain 39.62% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv499_10658.txt is 60.38% positive, but does contain 39.62% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv500_10251.txt is 60.37% positive, but does contain 39.63% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv501_11657.txt is 60.34% positive, but does contain 39.66% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv502_10406.txt is 60.33% positive, but does contain 39.67% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv503_10558.txt is 60.35% positive, but does contain 39.65% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv504_29243.txt is 60.35% positive, but does contain 39.65% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv505_12090.txt is 60.3% positive, but does contain 39.7% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv506_15956.txt is 60.32% positive, but does contain 39.68% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv507_9220.txt is 60.3% positive, but does contain 39.7% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv508_16006.txt is 60.31% positive, but does contain 39.69% negative words, it is therefore probably not a happy text.
    C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv509_15888.txt is 60.39% positive, but does contain 39.61% negative words, it is therefore probably not a happy text.
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          

  • How can I create a array with all files from a directory

    How can I create a array of files or varchar with all files from a directory?

    I thought the example could be improved upon. I've posted a solution on my blog that doesn't require writing the directory list to a table. It simply returns it as a nested table of files as a SQL datatype. You can find it here:
    http://maclochlainn.wordpress.com/2008/06/05/how-you-can-read-an-external-directory-list-from-sql/

  • List all files in a directory on a server that hosts the applet

    Hei :)
    I have a problem. I want to list all files in a directory on my server. ( http://www.foo.bar/tw )
    The applet is in the root folder ( http://www.foo.bar ).
    So i tried it like this
    File fi = new URL(getCodeBase() + "/all/").getFile();But when I try to list the files, I get a SecurityException.
    Can anyone help me out?
    Peace!
    LoCal

    http://search.java.sun.com/search/java/index.jsp?col=javaforums&qp=&qt=%2Blist+%2Bfile+%2Bserver

  • Finder not displaying all files in remote directory

    Sorry, this is a repost as I have gotten no response from my original request here: Finder not displaying all files in remote directory
    I've exported pictures from iPhoto on my iMac to a shared directory on my mac mini. When I access that directory from my iMac, I can see some but not all of the pictures. I know the pictures exported properly because I can see them all from the mac mini. I can open up a terminal window on my iMac and see all of the files; I can also open those files from the terminal.
    I'm running OSX 10.9.4 on both computers, with the mac mini also running OSX Server. I've placed a screen grab below from my iMac of what Finder sees vs what I can see from the terminal.
    Why isn't Finder displaying all of my files?

    thanks for responding
    Adding a new file to the shared folder results in me being able to see the new file from my clients regardless of where it was added from, however the "hidden" files do not suddenly pop up.
    I tried a few more experiments that had interesting results, but still didn't lead me to an answer.
    First I tried copying the files from the remote directory to a local directory; I did this in 2 different ways and had different results. Method A) I copied files from the mounted share to a local dir: "cp /Volumes/MyShare/dir/*.JPG .". Method B) I copied the files using secure copy: "scp user@server:/path/to/dir/*.JPG .".
    Method A resulted in Finder not being able to see the files in the local directory, while Method B did. This was interesting and lead me to suspect an issue with the way I am sharing the directory on the server. From Server settings I have both afp and smb checked. I tried enabling only one or the other and reconnecting; but this did not fix the problem.
    Next I tried exporting the photos from iPhoto again. Exporting them locally results in files that Finder can see. Exporting them to my server results the same bad behavior
    Getting desperate, I also tried renaming all of the files from "*.JPG" to "*.jpg" but this didn't help.
    One last experiment, I see the same behavior from both another Mac and a PC on my local network... FTP works fine.
    Any more ideas?

  • Is there any way to play all files in a directory by one url?

    Hi all,
    I am testing fms this days, I have put all my files(such as 1.mp3,2.mp3...n.mp3) in my directory.
    I can play single file fine with url like this:
    rtmp://localhost/mp3/mp3:x/2
    but i want to know is there any way to play all files in my direcotry?
    for example, user click the play button, the player(smp) automatic plays all files in the directory, link windows media server.
    Should I use playlist? Or there is another better way?
    Thanks a lot.

    Hi,
    FMS do not directly take a directory to play files, the file names have to be fetched some way (through script if needed) to make a playlist and then the play command needs to be repeated as many times.
    Thank you !

  • How to remove all files in a directory in java?

    I have tried method delete() of File ,
    but no effect!
    can anyone help me!
    thank you

    So, you have a directory and you want to delete all files in the directory. Here is some (untested) code:
    File dir = new File("C:\\tempdir");
    File[] files = dir.listFiles();
    for (int i = 0; i < files.length; ++i) {
      if (files.isFile()) {
    files[i].delete();
    Jesper

  • Creating an action that treats all files in a directory

    How can I make an action which changes the picture size and resolution for all files in a directory and saves the new versions of the files in a subdirectory?
    Thanks

    Macro Details wrote:
    First create your Sub directory. Then start the Action. Open file, Resisize save as (to Sub directory) then close the file.
    Now: File- Automate-Batch. Select your action and your folders and overide the open Command and the Save As Command.
    Frankly Norbert I think the Image processor way is easier but to each his own as they say.  

  • Deleting all files in a directory

    Hi,
    Is it possible to use cffile to delete all files in a
    directory. I have a function that creates a file in seperate parts
    and places the finished file into a folder. But I need a check to
    delete all files currently existing in said folder. I understand it
    is possible to query a folder for existing files and then use that
    query with cffile to delete the files... I just don't know how to
    do it.
    Thanks for your help

    I am not postivie, but I think I recall learning that the
    delete all function is prohibited via CF. You can delete specific
    files, though.
    If this is, in fact, the case, you could query the directory,
    and then loop through the resultant query, deleting each file one
    at a time.

  • Find & Replace text in html files

    This is my first real attempt at using Automator, and it has become increasingly frustrating for me. I love the idea of Automator, nice interface, and it appears to be so easy to use. But, I can't get it to actually DO anything and I don't understand why.
    Here is my goal:
    to batch process multiple html files to remove certain characters and words (or replace them with empty space).
    I currently open these files in Pages and do 6 separate Find & Replace commands for each file before I continue with my other processing tasks. This is very tedious and I believe the computer should be able to find & replace multiple items at one time. (I have used other utilities to do batch renaming and trimming file names before.)
    All I want to do is select a group of files (usually 25 at a time) and have Automator get rid of all the unwanted words and characters before I open each file for final processing in Pages. I found a set of Automator actions for TextEdit which includes a Find & Replace action, but I've wasted over an hour so far trying to get it to work.
    When I run the workflow, it acts like it's doing something, but the files remain unchanged. I have tried using actions such as Read Text File, Get Contents of TextEdit Document, Set Contents of TextEdit Document, along with 6 instances of Find & Replace, but I cannot get it to work.
    I'm at a point today where I cannot afford to mess around with this anymore. I have to do it the long way in Pages or else I'll never get it done, but I want to get these Automator workflows to work before I have to repeat this task. (I do this at least once a week right now.)
    Any ideas or suggestions? I've tried reading in the help menus and support pages, but perhaps I'm just not understanding something here.

    Any ideas or suggestions?
    You might be interested in using TextWrangler. It can perform batch find-and-replace changes across multiple selected files.
    Good luck!
    Andrew99

  • HTML  Parsers and reading all files in a directory

    Hello all,
    I was wondering if there was a html parser included in java. I am writing a program where I want to be able to search all the files in a directory tree for a particular string. I was able to read one file in a single directory but not in any other directory. How would I go about writing code to be able to access all files in directory that has multiple sub folders.
    Also, when I started to write my program I tried to use the DOM XML Parser to parse my html page. My logic behind this decision was that if you look at html code it is an xml document. But as I was trying to run my program I noticed that I had to convert my html document into xml format. I really don't want to have to build my own html parser. Is there a html parser that is included in Java. Oh my program is just your basic text program. No interfaces.
    Thanks for any help that you can provide
    Hockeyfan

    a particular string. I was able to read one file in
    a single directory but not in any other directory.
    How would I go about writing code to be able to
    access all files in directory that has multiple sub
    folders.
    You can do that several ways.
    Most likely you'll end up with some sort of recursive iteration over the directory tree.
    Not hard to write, somewhat harder to prevent memory problems if you end up with a lot of data.
    Also, when I started to write my program I tried to
    use the DOM XML Parser to parse my html page. My
    logic behind this decision was that if you look at
    html code it is an xml document. But as I was
    trying to run my program I noticed that I had to
    convert my html document into xml format. I really
    don't want to have to build my own html parser. Is
    there a html parser that is included in Java. Oh my
    program is just your basic text program. No
    interfaces.
    A VALID xhtml document is a valid XML document.
    Problem is that most HTML isn't xhtml.
    Another problem is that most HTML is fundamentally broken even to its own standards (which have always been based on SGML on which XML is also based).
    Browsers take that into account by being extremely lax on standards compliance and effectively making up tags as they go along to fill in the missing ones in the trees they parse.
    That's however not a standardised process and each browser handles it differently (and as a result most html will render differently in different browsers).
    Java contains a simple HTML parser in Swing, but it's primitive and will only parse a subset of HTML 2.0.
    There are almost certainly 3rd party libraries out there that can do better, both free and/or commercial.

  • Batch-process all files in a directory

    I'm relatively new to LabView. I'm using 5.1, and would like to open all the text files in a certain directory, and apply my formulaes to the data contained within each. How can I batch process a whole directory?

    Hi,
    first of all you need know names of files in your directory: for this purpose use File I/O / Advanced/List directory.vi. This vi get name of directory, pattern (*.txt for example) and returns array of path to files.
    For all path use Read From Spreadsheet File.vi that get name of file and return 1 or 2-d array of data.
    Now you can apply formula to data.

  • Utility VI for searching for the occurance of a string in all files in a directory

    Is anyone aware of a utility VI that can search for a string(s) in all
    file types such as doc, xls, ppt etc in a specified directory?

    Greetings,
    I'm having an issue (using 8.5) with a directory read in. I've attached my elementary VI. Basically I want to read in mutliple files (they will be the same array size), and analyze each file. I am confident I will be able to analyze the data as necessary, I'm just having a problem parsing the data. Verbally I know exactly what I need to do just doesn't seem to be working in labview. Reading in the directory isn't the hard part, but breaking up the 2D data into the number of files I have apparently is for me. 
    1. Read in (user defined) directory
    2. List the file names | # of files in the directory
    3. Perform MAX value and % analysis of data on AMP array 
    Any help would be greatly appreciated. Even if it's just verbally pointing me in the right direction. I've attached the VI and 3 example data files I read in.
    Thanks in advance...I really feel like I should know this one, but I usually deal in individual files, this is my first directory read.
    Best Regards,
    Chazzzmd 
    Attachments:
    labview text upload.zip ‏33 KB

  • How to get all files in one directory

    Hi there,
    is there any way to get all the files in one directory?
    e.g. a method
    File[] getAllFiles(String directory){
    Thank you

    Just out of interest, which part of the File API was confusing?
    http://java.sun.com/j2se/1.5.0/docs/api/index.html
    If you look down the left-hand side, you'll see a frame listing "All File". If you select "File" from that list, it opens up the API in the right-hand frame. Quite near the top you'll find "listFiles".
    I only ask as this (and other questions easily answered by looking at the API) are frequently asked. Did you overlook it when you read the API or did you just not read it?
    I really want to know. I think there is scope to cater for that behaviour within this site. A nice API finder would be good; something more intelligent than the search function (which people use less frequently even than the API docs).

Maybe you are looking for

  • Background Processing Option in Report

    Hi Fellow Abapers, I need to edit a report whereby there is an option to display further fields. Now if they select this option, the report NEEDS to run in the background and output to the file. This will later be retrieved byt the SAP Output Control

  • Independant window?

    ok. is it possible to make the link pull up in a separate window without closing the site. i want to be able to display a photo gallery by pressing a link and having it open in its own window. but without leaving the site. Dreamweaver has a behavoir

  • Can we peek into System V message queue?

    Hi, there. I have to processes A and B, talking through system v message queue. For debugging purposes, I wish to attach a third process C to that message queue and print out what info process A and B are exchanging. Is that possible? thanks

  • Missing font in Office 2007

    My Office Standard 2007 clearly states that a font Gill Sans is included but is missing from my list

  • CyberSource and Cartweaver

    I need help getting a CF version of the Cartweaver shopping cart to interact with the "Hosted Order Page" implementation of the CyberSource credit card processing system. CyberSource doesn't support ColdFusion, so I need to figure out how to use the