我试图将文件从一个文件夹复制到另一个文件夹,然后记录复制到日志文件中的所有文件的名称.两个文件夹都在同一目录中,我通过命令行获取该路径.在我的程序中,目前通过
argument3 = ARGV[2] + "\\"
Run Code Online (Sandbox Code Playgroud)
成功变为'c:\ user\alexander\desktop \'.然后我将桌面上的文件复制到桌面上已有的文件夹中
system "copy #{argument3}*.* #{argument3}TestFolder"
Run Code Online (Sandbox Code Playgroud)
这也成功完成了我从cmd输出和检查文件夹本身验证的内容.最后,我试图将文件名保存到路径为"c:\ user\alexander\desktop\log.txt"的日志文件中.我尝试通过使用来做到这一点
logFile = "c:\\user\\alexander\\desktop\\log.txt"
Dir.glob(argument3 + "*.*").each do |fileName|
File.open(logFile, 'a') {|file| file << "\n" + fileName}
end
Run Code Online (Sandbox Code Playgroud)
这没什么,让我logFile空虚.我尝试通过将File.open选项更改为'w'而不是'a' 来解决此问题,但仍然没有做任何事情.然后我认为我必须正确实施它,所以我试着放
Dir.glob(argument3 + "*.*").each do |fileName|
puts fileName
end
Run Code Online (Sandbox Code Playgroud)
作为一个完整性检查,但这也没有输出.我想要完成的是什么?如果是的话,我做错了什么,如果没有其他方法可以做到这一点?
编辑1:将Dir.glob参数更改为
Dir.glob("*")
Run Code Online (Sandbox Code Playgroud)
使它将当前目录文件写入日志.我认为这意味着我必须在我的argument3变量中有一些看不见的错字,但是当我这样做的时候
puts argument3 + "*"
Run Code Online (Sandbox Code Playgroud)
它的输出C:\用户\亚历山大\桌面*我试图串联的文件路径之前,我通过它作为参数传递给Dir.glob作为
filePath = argument3 + "*"
Dir.glob(argument3 + "*.*").each do |fileName|
File.open(logFile, 'a') {|file| file << "\n" + fileName}
end
Run Code Online (Sandbox Code Playgroud)
它仍然没有像我预期的那样工作.传递确切的文件路径是否有一些技巧Dir.glob …
我正在尝试将 swagger+swashbuckle 添加到我的 ASP.NET Core 项目中。我可以启动并运行 Swagger UI,但它完全是空的。我尝试四处查看并在https://github.com/domaindrivendev/Swashbuckle/issues/1058发现了类似的问题。这让我认为路由可能是问题所在,所以我尝试为我的控制器提供一个使用[Route("testroute")]方法而不是类的显式路由。这使得我添加的路由端点毫无问题地显示出来。
由于向每个端点添加显式路由不是最佳选择,我做错了什么以及如何修复它以大摇大摆地显示我的所有端点?
我的初创公司集成了 swagger
public class Startup
{
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true , reloadOnChange: true);
Configuration = builder.Build();
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().AddJsonOptions(x => x.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore);
// Register the Swagger generator, defining one or …Run Code Online (Sandbox Code Playgroud) asp.net-core ×1
c# ×1
command-line ×1
directory ×1
ruby ×1
swagger ×1
swagger-ui ×1
swashbuckle ×1