700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > shell访问php文件夹 Shell获取某目录下所有文件夹的名称

shell访问php文件夹 Shell获取某目录下所有文件夹的名称

时间:2021-04-03 11:37:27

相关推荐

shell访问php文件夹 Shell获取某目录下所有文件夹的名称

Shell获取某目录下所有文件夹的名称以下文字资料是由(历史新知网)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!

Shell获取某目录下所有文件夹的名称, 已知目录D:/temp,获取temp下所有文件夹的名称并输出,Shell怎么写?

方法有三,如下:

#!/bin/bash

#方法一

dir=$(ls-lD:/temp/|awk'/^d/{print$NF}')

foriin$dir

do

echo$i

done

#######

#方法二

fordirin$(lsD:/tmep/)

do

[-d$dir]&&echo$dir

done

##方法三

ls-lD:/temp/|awk'/^d/{print$NF}'

##其实同方法一,直接就可以显示不用for循环

php 获取目录下的所有文件夹名称

大致思路:

function traverseDir($dir){

if($dir_handle = @opendir($dir)){

while($filename = readdir($dir_handle)){

if($filename != "." && $filename != ".."){

$subFile = $dir.DIRECTORY_SEPARATOR.$filename; 要将源目录及子文件相连

if(is_dir($subFile)){ 若子文件是个目录

echo $filename.'

'; 输出该目录名称

traverseDir($subFile); 递归找出下级目录名称

}

}

}

closedir($dir_handle);

}

}

$dirNames = traverseDir("d:/dos"); 测试某目录

?>

VBS获取当前目录下所有文件夹名字

呵呵,原来是团友啊我写了一个!Set ws=WScript.CreateObject("wscript.shell")

w=ws.CurrentDirectory

Set fso=WScript.CreateObject("scripting.filesystemobject")

Set fs=fso.GetFolder(w)

Set f=fs.SubFolders

For Each uu In f

t=t & uu.Path & vbcrlf

Next

MsgBox t

使用VB获得目录下所有文件夹名称的问题

用FSO对象模型不是很好么,这种代码看的好痛苦哇!

C# 获取Ftp某个目录下的所有文件(不要文件夹)

我在之前做过一个FTP的客户端工具。

drw 文件夹

-rw 文件(有扩展名或无扩展名)

我是根据服务端返回的报文进行分析获取的列表。

给你一些代码片段:

/

/ 获取指定目录下的文件和文件夹。

/

/ 要获取的目录

/ 要发送到FTP服务器的密令。

/

public string[] GetFileList(string path, string WRMethods)从ftp服务器上获得文件列表

{

WebResponse response;

string[] downloadFiles;

int conut = 4;

StringBuilder result = new StringBuilder();

Connect(path);

if (FTPVariable.IsUseProxy_ftp)

{

reqFTP.Proxy = FtpProxy.GetFtpSelectProxy(FTPVariable.FtpCommand_transferProxyName);

}

reqFTP.ReadWriteTimeout = 12000;

如果不应销毁到服务器的连接,则为 true;否则为 false。默认值为 true。

reqFTP.Method = WRMethods;

try

{

response = (FtpWebResponse)reqFTP.GetResponse();

goto Ftp_lbl_03;

}

catch (WebException webex)

{

GetReply(webex.Message);

if (ReplyCode == 530) 未登录。

{

goto Ftp_lbl_04;

}

else if (ReplyCode == 550)

{

goto Ftp_lbl_04;

}

else

{

FtpManage.SetLog("获取列表超时,等候1秒后重试!");

goto Ftp_lbl_01;

}

}

Ftp_lbl_01:

try

{

FtpManage.SetLog("正在连接服务器 " + FtpRemoteHost);

response = GetRequest(path, WRMethods);

}

catch (WebException)

{

FtpManage.SetLog("获取列表超时,等候1秒后重试!");

downloadFiles = null;

System.Threading.Thread.Sleep(1000);

if (conut == 0)

{

goto Ftp_lbl_02;

}

conut--;

goto Ftp_lbl_01;

}

catch (Exception ex)

{

MSG.Show(ex.Message, Global.GetRS["msgTilteError"], MessageBoxButton.OK, MsgIco.Error);

FtpManage.SetLog("命令执行失败,原因:" + ex.Message);

downloadFiles = null;

return downloadFiles;

}

Ftp_lbl_03:

StreamReader reader = new StreamReader(response.GetResponseStream(), System.Text.Encoding.Default);中文文件名

string line = reader.ReadLine();

while (line != null)

{

result.Append(line);

result.Append("\n");

line = reader.ReadLine();

}

if (result.Length == 0)

{

return null;

}

to remove the trailing '\n'

result.Remove(result.ToString().LastIndexOf('\n'), 1);

reader.Close();

response.Close();

FtpManage.SetLog("命令已成功执行");

return result.ToString().Split('\n');

Ftp_lbl_04:

FtpManage.SetLog(ReplyInfo);

return null;

Ftp_lbl_02:

FtpManage.SetLog("550 获取列表失败,无法连接远程服务器!");

FtpManage.ftpmanage.IsRefurbish = true;

return null;

}

/

/ 获取指定目录下的文件和文件夹。

/

/ 要获取的目录

/

public string[] GetFileList(string path)从ftp服务器上获得文件列表

{

return GetFileList(FTPVariable.FtpURLhead + FtpRemoteHost + "/" + path, WebRequestMethods.Ftp.ListDirectory);

}

/

/ 获取指定目录下的文件和文件夹。

/

/

public string[] GetFileList()从ftp服务器上获得文件列表

{

return GetFileList(FTPVariable.FtpURLhead + FtpRemoteHost + "/", WebRequestMethods.Ftp.ListDirectory);

}

/

/ 获取目录和文件名,返回目录表。

/

/ 要获取的目录

/

public string[] GetCatalog_FileList(string path)

{

string[] fountainhead = GetFileList(FTPVariable.FtpURLhead + FtpRemoteHost + "/" + path, WebRequestMethods.Ftp.ListDirectoryDetails);

string[] Catalog = null;

if (fountainhead == null)

{

return null;

}

Catalog = new string[fountainhead.Length];

for (int i = 3; i < fountainhead.Length; i++)

{

Catalog[i - 3] += fountainhead[i].Substring(55, fountainhead[i].Length - 55) + "&";FileName

Catalog[i - 3] += fountainhead[i].Substring(30, 12) + "&";FileSize

Catalog[i - 3] += fountainhead[i].Substring(42, 13) + "&";AmendDate

Catalog[i - 3] += fountainhead[i].Substring(0, 3) + "&";

}

return Catalog;

}

请问ASP中如何获取某个目录中所有文件夹的名称?

fso.GetFolder(path)

shell编程如何获取指定目录下所有文件的名称,例:目录:/root/dira/下的 001.DAT…009.DAT 9个文件名称?

你刚才不是问过了么?

vb 如何读取某目录下所有文件及子文件夹

查找某目录下所有 文件 及 子文件夹

试一试不用 FileSystemObject 对象,只用基本控件的代码。

'例子需控件:Command1,List1,List2,File1,Dir1,都采用默认属性。

'例如,查找 C:\ ,带 '** 的语可修改

Dim ctFind As Boolean

Private Sub Form_Load()

Me.Caption = "查找所有文件及文件夹"

Command1.Caption = "查找"

List2.Visible = False: File1.Visible = False: Dir1.Visible = False

Label1.Caption = "就绪"

End Sub

Private Sub Form_Unload(Cancel As Integer)

End

End Sub

Private Sub Form_Resize()

Dim W As Long

On Error Resume Next

W = 720

List1.Move 0, 0, Me.ScaleWidth - W - 120, Me.ScaleHeight - 300

Command1.Move Me.ScaleWidth - W - 60, 300, W

Label1.Move 90, Me.ScaleHeight - 255, Screen.Width, 255

End Sub

Private Sub Command1_Click()

ctFind = Not ctFind

If ctFind Then

Command1.Caption = "取消"

Call FindDirFile("C:") '**查找 C:\ 下的所有文件和目录,或 C:\Windows 等

Command1.Caption = "查找"

Else

Command1.Caption = "查找"

End If

End Sub

Private Sub FindDirFile(ByVal nPath As String)

Dim I As Long, nDir As String, Ci As Long

ctFind = True

List1.Clear: List2.Clear

If Right(nPath, 1) <> "\" Then nPath = nPath & "\"

List1.AddItem "查找 " & nPath: List2.AddItem nPath

File1.Pattern = "*"

File1.System = True: File1.Hidden = True: File1.ReadOnly = True

On Error GoTo Cuo

Dir1.Path = nPath

On Error GoTo 0

Do

If List2.ListCount = 0 Then Exit Do

nPath = List2.List(0)

List2.RemoveItem 0

Dir1.Path = nPath

For I = 0 To Dir1.ListCount - 1

GoSub ShowGe

nDir = Dir1.List(I)

If Right(nDir, 1) <> "\" Then nDir = nDir & "\"

List1.AddItem "■" & nDir

List2.AddItem nDir

Next

File1.Path = nPath

For I = 0 To File1.ListCount - 1

GoSub ShowGe

List1.AddItem " " & nPath & File1.List(I)

Next

Loop

Label1.Caption = "查找完毕,共找到 " & List1.ListCount & " 个条目"

ctFind = False

Exit Sub

Cuo:

List1.AddItem "起始目录不存在:" & nPath

ctFind = False

Exit Sub

ShowGe:

Ci = Ci + 1

If Ci < 99 Then Return

Ci = 0

Label1.Caption = "已找到 " & List1.ListCount & " 个:" & nPath

DoEvents

If ctFind Then Return

End Sub

linux shell脚本怎么获取目录下所有txt文件名称

执行如下三条命令即可:

(1)、$script myresultfile

(2)、$ls -al *.txt

(3)、$exit

此时,该目录下的所有 txt 文件名称就会以长格式保存在 myresultfile 文件中了。

然后你再使用 SHELL 编程的功能把那些无用的列去掉即可。

分页:123

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。