如何使用批处理命令访问共享文件夹中超过4天的文件? [英] How to access files within shared folder which are older than 4 days using batch command ?

查看:182
本文介绍了如何使用批处理命令访问共享文件夹中超过4天的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我想在文本文件中显示超过4天的共享文件夹中的文件名。

我无法将生产服务器的用户名和密码传递给批处理命令来访问共享文件夹。



我尝试了什么:



1)FORFILES / P \\Test \abc / D -4 / S / Ccmd / c if @ isdir == FALSE echo / F / Q @path

运行以上命令后,我收到错误:

错误:不支持UNC路径(\\machine \ share)。



2)dir\\Test\abc/ b / s> fileslist.txt

在上面的命令中,没有规定传递D -4即获取超过4天的文件。

解决方案

< blockquote>如果你想坚持批处理文件,那么我建议使用 pushd popd 连接到UNC路径:

pushd | Microsoft Docs [ ^ ]

popd | Microsoft Docs [ ^ ]

 pushd \\Test\abc 
forfiles / D -4 / S / Ccmd / c if @ isdir = = FALSE echo / F / Q @path
popd


使用FileSystemObject - 引用 FileSystemObject对象| Microsoft Docs [ ^ ]

然后您可以获取上次修改日期并使用它,例如

设置FSO = CreateObject(Scripting.FileSystemObject)
set oFile = FSO.GetFile(sFile)

wscript.echoFile last modified:& objFile.DateLastModified





编辑...找到信用:文件修改日期(VBScript) [ ^ ]


Hello,

I want to display file names, in text file, from shared folder which are older than 4 days.
I can not pass username and password of production server to batch command to access shared folder.

What I have tried:

1) FORFILES /P \\Test\abc /D -4 /S /C "cmd /c if @isdir==FALSE echo /F /Q @path"
On running above command, I am getting an error :
ERROR: UNC paths (\\machine\share) are not supported.

2) dir "\\Test\abc" /b /s > fileslist.txt
In above command, there is no provision to pass D -4 i.e. to get files which are older than 4 days.

解决方案

If you want to stick with a batch file, then I'd suggest using pushd and popd to connect to the UNC path:
pushd | Microsoft Docs[^]
popd | Microsoft Docs[^]

pushd \\Test\abc
forfiles /D -4 /S /C "cmd /c if @isdir==FALSE echo /F /Q @path"
popd


Use the FileSystemObject - reference FileSystemObject object | Microsoft Docs[^]
You can then get hold of the last modified date and use that e.g.

Set FSO = CreateObject("Scripting.FileSystemObject")
set oFile = FSO.GetFile(sFile)

wscript.echo "File last modified: " &  objFile.DateLastModified



Edit … found the Credit: File Modified Date (VBScript)[^]


这篇关于如何使用批处理命令访问共享文件夹中超过4天的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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