線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:3956
推到 Plurk!
推到 Facebook!

尋找檔案是否存在己知的資料夾內??

尚未結案
Nicole
一般會員


發表:11
回覆:11
積分:4
註冊:2002-08-12

發送簡訊給我
#1 引用回覆 回覆 發表時間:2002-10-28 00:15:10 IP:211.75.xxx.xxx 未訂閱
想請教各位高手一下: 假設我想要上傳三張圖片,其檔名分別為 A08010101s.jpg A08010101m.jpg A08010101b.jpg 但是在上傳前我要先去搜尋在D:\picture下是否有這三個檔案存在? (在edit1會先輸入A0801再去做搜尋) 若是存在的話將其檔名印在memo中 且分別將其圖片放入三個image中 不知這樣的程式如何撰寫?? 謝謝~~
RaynorPao
版主


發表:139
回覆:3622
積分:7025
註冊:2002-08-12

發送簡訊給我
#2 引用回覆 回覆 發表時間:2002-10-28 08:46:02 IP:203.73.xxx.xxx 未訂閱
引言: 想請教各位高手一下: 假設我想要上傳三張圖片,其檔名分別為 A08010101s.jpg A08010101m.jpg A08010101b.jpg 但是在上傳前我要先去搜尋在D:\picture下是否有這三個檔案存在? (在edit1會先輸入A0801再去做搜尋) 若是存在的話將其檔名印在memo中 且分別將其圖片放入三個image中 不知這樣的程式如何撰寫?? 謝謝~~
用 FindFirstFile 及 FindNextFile 在 MSDN 及 Platform SDK 中可以查到更詳細的說明 sample code 如下
   HRESULT hr=S_FALSE;
   const char* szPath="D:\\Picture\\a0801*.jpg";
   WIN32_FIND_DATA wfd;
   HANDLE hFile=INVALID_HANDLE_VALUE;       ZeroMemory(&wfd, sizeof(WIN32_FIND_DATA));       hFile=FindFirstFile(szPath, &wfd);
   if(hFile==INVALID_HANDLE_VALUE)
   {
      hr=GetLastError();
      printf("\nFindFirstFile failed, error code=lX", hr);
   }
   else
   {
      printf("\nFindFirstFile succeed, cFileName=%s", wfd.cFileName);
   }
   while(hFile!=INVALID_HANDLE_VALUE && FindNextFile(hFile, &wfd))
   {
      printf("\nFindNextFile succeed, cFileName=%s", wfd.cFileName);
   }
   FindClose(hFile);
------
-- 若您已經得到滿意的答覆,請適時結案!! --
-- 欲知前世因,今生受者是;欲知來世果,今生做者是 --
-- 一切有為法,如夢幻泡影,如露亦如電,應作如是觀 --
ccchen
版主


發表:61
回覆:940
積分:1394
註冊:2002-04-15

發送簡訊給我
#3 引用回覆 回覆 發表時間:2002-10-28 09:56:51 IP:61.219.xxx.xxx 未訂閱
procedure TForm1.Button1Click(Sender: TObject);
  procedure AddPicture(filename:string;img:TImage);
  begin
    if FileExists(Filename) then begin
      Memo1.lines.add(FileName);
      img.loadFormFile(FileName);
    end;
  end;
begin
  AddPicture('d:\picture\A08010101s.jpg',image1);
  AddPicture('d:\picture\A08010101m.jpg',image2);
  AddPicture('d:\picture\A08010101b.jpg',image3);
end;
Nicole
一般會員


發表:11
回覆:11
積分:4
註冊:2002-08-12

發送簡訊給我
#4 引用回覆 回覆 發表時間:2002-11-03 01:08:18 IP:211.75.xxx.xxx 未訂閱
若是如ccchen 版主這樣寫法的話只能抓取這三個檔案 我希望能夠很動態的判斷及抓取任何的檔案 並且能夠上傳是ftp站且放在不同的目錄夾內 是按一個按鍵就能完成這所有的動作.... 以下是我大概寫的程式,不知邏輯方面是否有出錯?? procedure TForm1.Button1Click(Sender: TObject); var localfile:string; remotefile:string; thedir:string; i:integer; begin memo1.Clear; //設定openpicturedialog的啟始目錄及 filter的過濾條件 openpicturedialog1.InitialDir:='d:\tool\pic'; openpicturedialog1.Filter:='all files(*.*)|*.*'; for i:=0 to openpicturedialog1.ComponentCount -1 do  //測試檔案是否存在  if FileExists('d:\tool\pic\'+edit1.Text+inttostr(i)+'.jpg') then   begin   //將擁有edit1.text開頭之檔案呈現在memo1中   memo1.Lines.Add('d:\tool\pic\'+edit1.Text+inttostr(i)+'.jpg');   image1.Picture.LoadFromFile('d:\tool\pic\'+edit1.Text+inttostr(i)+'.jpg');   end;    if NMFTP1.Connected then     NMFTP1.Disconnect   else     begin      NMFTP1.Host := '*.*.*.*;      NMFTP1.UserID := '******';      NMFTP1.Password := '*******';      NMFTP1.Connect;        end;      if NMFTP1.connected then    begin     Memo2.Clear;     NMFTP1.NList;     Thedir:='public_html/picture/s';     NMFTP1.ChangeDir(TheDir);           LocalFile :=memo1.Lines[0];           remotefile:=ExtractFileName(localfile);           NMFTP1.Mode(MODE_BYTE);           NMFTP1.Upload(LocalFile, RemoteFile);       end;    if NMFTP1.Connected then     NMFTP1.Disconnect   else     begin      NMFTP1.Host := '*.*.*.*';      NMFTP1.UserID := '********';      NMFTP1.Password := '*******';      NMFTP1.Connect;     end;      if NMFTP1.connected then    begin     Memo2.Clear;     NMFTP1.NList;     Thedir:='public_html/picture/m';     NMFTP1.ChangeDir(TheDir);           LocalFile :=memo1.Lines[1];           remotefile:=ExtractFileName(localfile);           NMFTP1.Mode(MODE_BYTE);           NMFTP1.Upload(LocalFile, RemoteFile);           SHOWMESSAGE('圖片上傳成功');       end;        end;    謝謝^^     發表人 -
00156
高階會員


發表:45
回覆:195
積分:112
註冊:2002-06-01

發送簡訊給我
#5 引用回覆 回覆 發表時間:2002-11-03 07:57:29 IP:61.56.xxx.xxx 未訂閱
使用OpenDialog直接選取會更快,可以將Options設成ofFileMustExist。 然後將選取後的結果直接放入memo裡 例: if OpenDialog1.Execute then memo1.Add(OpenDialog1.FileName);
系統時間:2024-07-03 0:41:25
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!