我正在尝试将代码从bash转换为PowerShell,如下所示:
在bash中:
./searchfolder/something
./searchfolder/0.15/something
./searchfolder/0.25/something
我的意思是“找到”命令找到
./destinationfolder/something
./destinationfolder/0.15/something
./destinationfolder/0.25/something
和“copy”命令复制新目录中的文件(具有保留文件夹结构)
#include <zmq.hpp>
#include <string>
#include <iostream>
#include <time.h>
#include "math.h"
int main ()
{
// Prepare our context and socket
zmq::context_t context (1);
zmq::socket_t socket (context, ZMQ_REQ);
clock_t t_ini, t_end;
double secs;
// We take the clock value before the call to process.
t_ini = clock();
std::cout << "Conectando al servidor python zeroMQ…" << std::endl;
socket.connect ("tcp://localhost:5555");
zmq::message_t request (20);
memcpy (request.data (), "Hola Servidor Python", 20);
socket.send (request);
zmq::message_t reply;
socket.recv (&reply);
// I make cast conversion to string the response
std::string replyMessage = std::string(static_cast<char *>(reply.data()), reply.size());
std::cout << "Recibiendo respuesta desde el servidor: " + replyMessage << " " << std::endl;
t_end = clock();
secs = (double)(t_end - t_ini) / CLOCKS_PER_SEC;
printf("%.16g miliseconds", secs * 1000.0);
return 0;
}
我该怎么做?提前谢谢。
答案 0 :(得分:1)
如何在Copy-Item命令中使用Filter参数?这可能会让你接近。
cp ".\searchfolder" -Recurse -Filter "something" -Destination ".\destinationfolder"
cp
是Copy-Item
BTW的别名。
答案 1 :(得分:0)
这假设您正在寻找C:\ temp中的文本文件并将它们移动到C:
Get-Childitem –Path C:\Temp -Recurse -Include *.txt* | ForEach-Object { mv $_.fullName c:\ }
问候!
答案 2 :(得分:0)
我假设这将是文件夹结构。 Sourcefolder中只有一个子目录。
SourceFolder
--f1
-test.txt
--f2
-test.txt
--f3
-other.txt
并复制具有名为test
的文件的文件夹Destination
--f1
-test.txt
--f2
-test.txt
脚本
cd D:\Vincent\PSTesting
$Path = 'Searchfolder'
Get-ChildItem $Path -Recurse -Filter *Test* -File | foreach {
$SourceFolder = $_.Directory -replace "^.*$Path"
Copy-Item -Path $Path\$SourceFolder -Destination "D:\Vincent\PSTesting\Destinationfolder\" -Verbose -Recurse
}