小编Sea*_*ght的帖子

查找:删除目录后无法chdir到目录错误消息

我正在开发一个项目来自动删除超过一天的特定目录.我有以下代码工作:

find Directory/ -type d -name "Directory.To.Delete.*" -mtime +1 -exec rm -rf {} \;
Run Code Online (Sandbox Code Playgroud)

它运行正常并按预期删除目录(和内容),但它总是以错误结束:

find: cannot chdir to Directory/ : No such file or directory

有没有办法运行此代码而不会遇到此错误?我不明白为什么这段代码在删除目录后尝试chdir.

unix bash shell automation

3
推荐指数
1
解决办法
2289
查看次数

迭代地在Perl中的匹配行之后抓取多行?

我想要一个哈希结构,每个以>开头的行是键,而直到下一个>的行是该键的值:

while (<DATA>) {
    $line1 = $_;
    chomp($line1);

    if ($line1 =~ /^>/) {
        while (<DATA>) {
            last if $line1 =~ /^>/;
            $value .= $_;
        }
        $hash{$line1} = $value;
    }
}

foreach my $key(%hash) {
    print "$key :$hash{$key}\n";
}

__DATA__
>label1 
line1\n
line2\n
>label2
line1\n
line2\n
Run Code Online (Sandbox Code Playgroud)

perl hash pattern-matching

3
推荐指数
1
解决办法
676
查看次数

执行while循环以检查文件是否存在

我正在为我工​​作的公司编写一个C#程序,它将启动一个创建PDF的PHP脚本,然后打开PDF文件.现在,我有:

// launch the PHP page to generate my pdf report
Process.Start(phpFile);

// wait for the report to exist
Thread.Sleep(waitTime);

// open the report
Process.Start(filePath);
Run Code Online (Sandbox Code Playgroud)

现在,我不是一个整体的粉丝" Sleep()在指定的时间内希望文件存在时完成".所以我的问题是,使用do循环是否可行/更好并说:

do
{
    // Do nothing until the file exists 
} while (!File.Exists(filePath));
Run Code Online (Sandbox Code Playgroud)

c# loops

3
推荐指数
2
解决办法
4837
查看次数

从日期字符串中获取年份

我想检查当前年份是否大于日期字符串(DMY),这是我的代码

$OldDate = "09-30-2011";
$OldYear = strtok($OldDate, '-');
$NewYear = date("Y");

if ($OldYear < $NewYear) {
    echo "Year is less than current year"   
} else {
    echo "Year is greater than current year";
}
Run Code Online (Sandbox Code Playgroud)

html php

3
推荐指数
1
解决办法
1万
查看次数

Linux:将两个不同文件中的数据合并为一个,如何完成?

我有两个文件,一个用ip填充,一个ip在一行,另一个文件叫host,它包含ip文件中ip的解析名称.我正在尝试创建一个hosts文件,所以我试图从ip的文件中取出第一行,然后从hosts文件中插入一个空白然后插入解析主机,并对每个ip/hosts执行相同的操作.实现这一目标的最佳方式是什么?

ip的文件如下所示:

1.1.1.1
1.1.1.2
1.1.1.3
1.1.1.4

hosts文件如下所示:

server01
server02
server03
server04

linux bash

2
推荐指数
1
解决办法
480
查看次数

如何按用户给出的完整路径打开文件?

我写了这段代码.我想向用户询问文件的完整路径,然后转到该路径并打开文件.但不幸的是程序无法找到该文件.例如,我在这个路径G:\ project 2 \newfile中创建了一个文件但是当我在c ++控制台中输入它时,它说"打开文件时出错".我真的需要解决这个问题.请帮我解决一下这个.谢谢

#include <iostream>
#include <fstream>
#include <conio.h>
#include <windows.h>

using namespace std;

int main()
{
    string address;
    cout << "Enter the full path of the file" << endl;
    cin >> address;
    ifstream file(address.c_str());

    if (!file) {
        cout << "Error while opening the file" << endl;
        return 1;
    }

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ file

2
推荐指数
1
解决办法
2158
查看次数

cd命令不能与execvp一起使用

#include <stdio.h>
#include <sys/types.h>
#include <string.h>

int main()
{
    char *ip;
    char *temp[10];
    pid_t pid;

    pid = fork();

    if (pid == 0) {
        int i = 0;

        do {
            gets(ip);

            temp[0] = strtok(ip, " ");
            while (temp[++i] != NULL) {
                temp[i] = strtok(NULL," ");
            }

            pid_t pid2;

            pid2 = fork();
            if (pid2 == 0) {
                execvp(temp[0], temp);
            }
        } while(strcmp(temp[0], "quit"));

        if (!strcmp(temp[0],"quit")) {
            return;
        }
    } else if (pid < 0) {
        fprintf(stderr,"error in creating child");
    } else if …
Run Code Online (Sandbox Code Playgroud)

c linux

2
推荐指数
1
解决办法
7029
查看次数

为除尖括号外的非字符之外的每个单词添加标签

我正在处理包含图像标记和新行标记的文本段落.目标是通过将所有单词charachter的颜色更改为白色来使所有非单词charechter显示清楚.我正在使用java作为编程语言.我想使用正则表达式,但问题它改变了图像标签内的单词charechters.

String RegEx = "\\w|[àÀâÂäÄáÁéÉèÈêÊëËìÌîÎïÏòÒôÔöÖùÙûÛüÜçÇ’ñ]";

try {
    Pattern mypattern = Pattern.compile(RegEx, Pattern.CASE_INSENSITIVE);
    Matcher myMatcher = mypattern.matcher(sentence);
    int offset = 0;
    while (myMatcher.find()) {
        int start = myMatcher.start() + offset;
        int end = myMatcher.end() + offset;
        sentence = sentence.substring(0, start) + "<font color=\"white\">" + sentence.substring(start, end) + "</font>" + sentence.substring(end, sentence.length());
        offset += 28;
    }
} catch (Exception e) {
    e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)

所需结果的例子.输入: Most implementations<img title="hello:" alt="hello:{}" src="http://images.doctissimo.fr/hello.gif" class="wysiwyg_smiley" /> provide ASDF as a module, and you can …

html java regex

2
推荐指数
1
解决办法
427
查看次数

Java在资源文件夹中写入.txt文件

我试图在资源文件夹中写一个.txt文件,但它没有写任何东西.通过执行以下操作,我能够读取相同的.txt文件:

Scanner scanner = null;
InputStream IS = MyClass.class.getResourceAsStream("/File/My FileH");
scanner = new Scanner(IS);
Run Code Online (Sandbox Code Playgroud)

但是当谈到写作时,我尝试过:

PrintWriter writer =  new PrintWriter(
    new File(this.getClass().getResource("/File/My FileH").getFile()));
writer.println("hello");
writer.close();
Run Code Online (Sandbox Code Playgroud)

有关如何在该文件夹中写入的任何建议?

java

2
推荐指数
1
解决办法
1万
查看次数

关于C的重入

如果您有一个库中的函数f_func()并且您知道它不可重入,那么您将如何在线程环境(POSIX)中使用它?您无法访问库的源代码.

c reentrancy

2
推荐指数
1
解决办法
96
查看次数

标签 统计

bash ×2

c ×2

html ×2

java ×2

linux ×2

automation ×1

c# ×1

c++ ×1

file ×1

hash ×1

loops ×1

pattern-matching ×1

perl ×1

php ×1

reentrancy ×1

regex ×1

shell ×1

unix ×1