list.files()找不到文件夹中的所有文件

编程入门 行业动态 更新时间:2024-10-27 20:35:01
本文介绍了list.files()找不到文件夹中的所有文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试将一些".xls"加载到R中.该文件夹包含8个.XLS文件和8个.csv文件,这些文件是通过手动打开.xls文件并将其另存为.csv文件制成的.我意识到我可以使用 gdata 包中的 read.xls()直接加载.xls文件,这对以.xls格式接收数据很有用.但是,当我在3个最新的.xls文件中使用 list.files()时,该列表会丢失.但是,包含了与它们关联的.csv.如果我打开文件并将其转换为.xls,然后再次运行 list.files(),则会显示它们;如果在资源管理器中重命名它们,则当我运行 list时,它们将不会显示.文件.Excel文件可能来自不同地区的Excel版本,就像它们来自不同国家/地区的办公室一样,但是我想这不会产生影响.

I am trying to load some ".xls" into R. the folder contains 8 .XLS files and 8 .csv files which I made by manually opening up the .xls files and saving as a .csv. I realised that I could use read.xls() from the gdata package to load the .xls files directly which is helpful as the data is received in .xls format. however when I use list.files() in the 3 newest .xls files are missed off the list. Their associated .csv's are however included. if I open the files and convert them to .xls then run list.files() again they show up, if I rename them in the Explorer they will not show up when I run list.files again. The Excel files may come from a different region's version of Excel as they come from an office in a different country, but I wouldn't have thought that would have an effect.

文件通过电子邮件发送给我,因此,作为一个实验,我创建了一个新文件夹并将文件从Outlook保存到新文件夹,当我运行 list.files()时的结果是相同的,当我转换它们时也是如此.

The files were emailed to me and so as an experiment I created a new folder and saved the files from Outlook to the new folder, the result when I ran list.files() was the same, also when I converted them.

list.files(getwd())

返回

character(0)

如果我使用 list.files(getwd())或指定文件扩展名,则没有区别.

It makes no difference if I use list.files( getwd() ) or specify the file extension.

我想知道自己缺少什么,因此可以避免在运行脚本时单独打开每个文件或冒丢失文件的风险.

I would like to know what I am missing so i can avoid having to open each file individually or risk missing files when I run my script.

此问题的道歉无法再现.

Apologies for this question not being reproducible.

编辑

在Jbaum的建议下,运行了以下代码并返回了结果

At the suggestion of Jbaum the following code was run and results were returned

shell(sprintf('dir /b %s', normalizePath(getwd())), intern=TRUE) [1] "'\\\\\\ **File path**'" [2] "CMD.EXE was started with the above path as the current directory." [3] "UNC paths are not supported. Defaulting to Windows directory." [4] "The system cannot find the file specified." attr(,"status") [1] 1 Warning message: running command 'C:\WINDOWS\system32\cmd.exe /c dir /b \\\\ **File path**' had status 1

注意:我已将文件路径替换为**文件路径**,并将反斜杠的数量增加了一倍,因此它们显示为R

Note: I have replaced the file path with **File path**, and have doubled the number of backslashes so they display as in R

推荐答案

问题是与公司PC的网络同步有关,而与R无关.

我正在使用的系统将PC的C驱动器中的所有文件同步到网络驱动器,所有程序的默认设置是在PC连接到网络时查看网络驱动器上的文件.

The system that I am using syncs all files from the C drive of the PC the to the network drive, the default setting for all programs is to look at the files on the network drive when the PC is connected to the network.

但是,当我从Outlook传输文件时,它们存储在该文件夹的本地实例中,而没有网络文件,因此对于查看该网络实例的R不可见.

However when I transferred the files from outlook they were stored on the local instance of the folder and no the networked one, making them invisible to R which viewed the network instance.

当我使用Excel转换文件时,默认情况下,新文件会保存到网络中,以使R可以看到它们.当系统执行同步过程时,R最终可以访问所有文件.

When I converted the files using Excel the new files were by default saved to the network allowing them to be seen by R. when the system went through the synchronisation process all files were finally accessible by R.

将来避免此问题的一种方法是,如果看不见文件则进行手动同步,以检查这不是问题.

A way to avoid this problem in future is to do a manual sync if the files are not visible to check this is not the problem.

更多推荐

list.files()找不到文件夹中的所有文件

本文发布于:2023-11-13 10:09:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1584099.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   找不到   夹中   list   files

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!