为什么不能删除带有波浪号的文件? [英] Why Can't I Delete Files With A Tilde?

查看:133
本文介绍了为什么不能删除带有波浪号的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Elixir 1.3.2

Elixir 1.3.2

Erlang / OTP 19

Erlang/OTP 19

Windows 7(标准用户和管理员)

Windows 7 (Standard User and Administrator)

我正在尝试破解一个小的Elixir脚本,以将文件提交到git中。为了确保我不会意外暂存emacs创建的临时文件,我要做的第一件事是File.rm( *〜)。但是,这就是我得到的:

I'm trying to hack together a small Elixir script to wrap around commiting files to git. The first thing I do, in order to insure I don't accidentally stage temporary files created by emacs is File.rm("*~"). However, this is what I get:

iex(2)> File.rm("*~")
{:error, :eio}

因此我尝试了 File.rm( *。*〜)。结果相同。当我以标准用户身份(这是我通常在Windows上的工作方式)或管理员身份运行时,也会得到相同的行为,因此似乎也没有任何权限。

So I tried File.rm("*.*~"). Same result. I get the same behavior when I run as either a Standard User (which is how I normally work on Windows) or as an administrator so it doesn't seem to be anything with permissions either.

所以我将文件捕获到列表中。

So I captured the files into a list.

iex(15)> {:ok,files} = File.ls
{:ok,
 [".git", ".gitattributes", ".gitignore", "add.factor", "async_ut",
  "async_ut.cs", "cng_maint", "codecvg.cmd", "codecvg_rkt.cmd",
  "codecvg_rkt.cmd~", "CreateBr.vbs", "DevSandbox", "distillery", "dk.cmd",
  "example.scm", "example.sql", "factor", "fsele", "fsharp", "glp.vbs",
  "lwwtww.org", "mrgmain.cmd", "MrgMain.vbs", "mrgtrunk.cmd", "mrgtrunk.cmd~",

(删节以节省空间)

我可以检查列表中包含的字符串,回到真实。因此,我没有想过波浪号在那里。

I can check for the strings in the list containing ~ and it comes back true. So I'm not imagining the tilde being there.

我在其中创建了一个名为 test.txt 的临时文件。目录。 File.rm 删除了那个问题,所以似乎与导致问题的有关。我还尝试了这些:

I created a temporary file called test.txt in the directory. File.rm removed that one just fine so it seems to be something about the ~ which is causing the issue. I also tried these:

iex(7)> File.rm("*\~")
{:error, :eio}
iex(8)> File.rm("*\7F") #7F is hex code of ~
{:error, :eio}

$ b $的十六进制代码b

如您所见,没有运气。

No luck as you can see.

使用Elixir和File.rm搜索有关:eio 的任何内容并没有提供任何帮助。我可以尝试安装1.4.0,看看是否有效果,但是我只是想看看我在这里是否缺少一些愚蠢而明显的东西。

Googling for anything about :eio with Elixir and File.rm didn't turn up anything helpful. I can try installing 1.4.0 to see if that has an effect but I just wanted to see if I was missing something dumb and obvious here.

我也有cygwin在机器上,所以我尝试用这种方式删除文件。 rm *〜的工作完全符合预期(在标准用户下)。

I've also got cygwin on the machine so I tried removing the files that way. rm *~ worked exactly as expected (under a standard user).

似乎这是特定于Erlang的问题,但我首先在这里提出。我是否在做明显的错误?

It seems as if this is somehow an Erlang specific issue but I'm aksing here first. Am I doing something obviously wrong?

推荐答案

File.rm / 1 不会自动处理通配符,您需要使用 Path.wildcard / 2 函数:

File.rm/1 won't process wildcards automatically as far as I know, you need to use the Path.wildcard/2 function:

File.rm(Path.wildcard("*~"))

Path.wildcard('*~') |> Enum.each(fn x -> File.rm(x) end)

文件(可能是更一般的情况)。

for more than one file (which is probably the more general case).

这篇关于为什么不能删除带有波浪号的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆