shell访问php文件夹,Shell获取某目录下所有文件夹的名称
Shell獲取某目錄下所有文件夾的名稱以下文字資料是由(歷史新知網(wǎng)www.lishixinzhi.com)小編為大家搜集整理后發(fā)布的內(nèi)容,讓我們趕快一起來看一下吧!
Shell獲取某目錄下所有文件夾的名稱, 已知目錄D:/temp,獲取temp下所有文件夾的名稱并輸出,Shell怎么寫?
方法有三,如下:
#!/bin/bash
#方法一
dir=$(ls?-l?D:/temp/?|awk?'/^d/?{print?$NF}')
for?i?in?$dir
do
echo?$i
done
#######
#方法二
for?dir?in?$(ls?D:/tmep/)
do
[?-d?$dir?]?&&?echo?$dir
done
##方法三
ls?-l?D:/temp/?|awk?'/^d/?{print?$NF}'
##?其實(shí)同方法一,直接就可以顯示不用for循環(huán)
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)){ 若子文件是個(gè)目錄
echo $filename.'
'; 輸出該目錄名稱
traverseDir($subFile); 遞歸找出下級(jí)目錄名稱
}
}
}
closedir($dir_handle);
}
}
$dirNames = traverseDir("d:/dos"); 測(cè)試某目錄
?>
VBS獲取當(dāng)前目錄下所有文件夾名字
呵呵,原來是團(tuán)友啊我寫了一個(gè)!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對(duì)象模型不是很好么,這種代碼看的好痛苦哇!
C# 獲取Ftp某個(gè)目錄下的所有文件(不要文件夾)
我在之前做過一個(gè)FTP的客戶端工具。
drw 文件夾
-rw 文件(有擴(kuò)展名或無擴(kuò)展名)
我是根據(jù)服務(wù)端返回的報(bào)文進(jìn)行分析獲取的列表。
給你一些代碼片段:
/
/ 獲取指定目錄下的文件和文件夾。
/
/ 要獲取的目錄
/ 要發(fā)送到FTP服務(wù)器的密令。
/
public string[] GetFileList(string path, string WRMethods)從ftp服務(wù)器上獲得文件列表
{
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;
如果不應(yīng)銷毀到服務(wù)器的連接,則為 true;否則為 false。默認(rèn)值為 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("獲取列表超時(shí),等候1秒后重試!");
goto Ftp_lbl_01;
}
}
Ftp_lbl_01:
try
{
FtpManage.SetLog("正在連接服務(wù)器 " + FtpRemoteHost);
response = GetRequest(path, WRMethods);
}
catch (WebException)
{
FtpManage.SetLog("獲取列表超時(shí),等候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("命令執(zhí)行失敗,原因:" + 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("命令已成功執(zhí)行");
return result.ToString().Split('\n');
Ftp_lbl_04:
FtpManage.SetLog(ReplyInfo);
return null;
Ftp_lbl_02:
FtpManage.SetLog("550 獲取列表失敗,無法連接遠(yuǎn)程服務(wù)器!");
FtpManage.ftpmanage.IsRefurbish = true;
return null;
}
/
/ 獲取指定目錄下的文件和文件夾。
/
/ 要獲取的目錄
/
public string[] GetFileList(string path)從ftp服務(wù)器上獲得文件列表
{
return GetFileList(FTPVariable.FtpURLhead + FtpRemoteHost + "/" + path, WebRequestMethods.Ftp.ListDirectory);
}
/
/ 獲取指定目錄下的文件和文件夾。
/
/
public string[] GetFileList()從ftp服務(wù)器上獲得文件列表
{
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;
}
請(qǐng)問ASP中如何獲取某個(gè)目錄中所有文件夾的名稱?
fso.GetFolder(path)
shell編程如何獲取指定目錄下所有文件的名稱,例:目錄:/root/dira/下的 001.DAT…009.DAT 9個(gè)文件名稱?
你剛才不是問過了么?
vb 如何讀取某目錄下所有文件及子文件夾
查找某目錄下所有 文件 及 子文件夾
試一試不用 FileSystemObject 對(duì)象,只用基本控件的代碼。
'例子需控件:Command1,List1,List2,File1,Dir1,都采用默認(rèn)屬性。
'例如,查找 C:\ ,帶 '** 的語(yǔ)可修改
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 & " 個(gè)條目"
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 & " 個(gè):" & nPath
DoEvents
If ctFind Then Return
End Sub
linux shell腳本怎么獲取目錄下所有txt文件名稱
執(zhí)行如下三條命令即可:
(1)、$script myresultfile
(2)、$ls -al *.txt
(3)、$exit
此時(shí),該目錄下的所有 txt 文件名稱就會(huì)以長(zhǎng)格式保存在 myresultfile 文件中了。
然后你再使用 SHELL 編程的功能把那些無用的列去掉即可。
分頁(yè):123
總結(jié)
以上是生活随笔為你收集整理的shell访问php文件夹,Shell获取某目录下所有文件夹的名称的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php mms,PHP代码示例_PHP账
- 下一篇: 上海欢乐谷让带吃的吗