AXForum  
Вернуться   AXForum > Microsoft Dynamics AX > DAX Blogs
DAX
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 04.05.2009, 14:05   #1  
Blog bot is offline
Blog bot
Участник
 
25,475 / 846 (79) +++++++
Регистрация: 28.10.2006
Dynamics AX Geek: Finding files with WinAPI
Источник: http://axgeek.spaces.live.com/Blog/c...DB13!150.entry
==============
 Axapta’s WinAPI class has a bunch of static methods to handle files. The code example below shows how to utilize some of these methods to find files.

The two methods used to fetch all files matching the search criteria are findFirstFile() and findNextFile(). Don’t forget to clean up after yourself with findClose().

 

The code also uses three different find methods:

  • fileExists(_name) returns true, if _name is an existing file
  • folderExists(_name) returns true, if _name is an existing file or folder
  • pathExists(_name) returns true, if _name is an existing folder
The example uses the infolog for output. As with any infolog beware of performance and limitation to 10.000 lines.



 

X++:
 static void FindFile(Args _args)
 {
  #File

  FileName fullFileName(FileName _path, FileName _fileName)
  {
   pathName;
   fileName;
   fileExtension;
  ;
  [pathName,fileName,fileExtension] = fileNameSplit(_fileName);
 
  return _path + '\\' + fileName + fileExtension;
  }
 
  void findFiles(FileName _path, 
  FileName _fileName, 
  boolean _inclSubDir = true, 
  FileName _prefix = fullFileName(_path,_fileName))
  {
   fileName;
  int hdl;
  ;
 
  setprefix(_prefix);
 
  if (WinAPI::folderExists(_path))
  {
  [hdl,fileName] = WinApi::findFirstFile(fullFileName(_path,_fileName));
 
  while (fileName)
  {
  if (WinAPI::fileExists(fullFileName(_path,fileName)))
  info(fileName);
 
  fileName = WinApi::findNextFile(hdl);
  }
 
  WinApi::findClose(hdl);
 
  if (_inclSubDir)
  {
  [hdl, fileName] = WinAPI::findFirstFile(_path+'\\'+#AllFiles);
 
  while (fileName)
  {
  if (strlwr(fileName) != strlwr(_fileName) &&
  strlwr(fileName) != strlwr('.') &&
  strlwr(fileName) != strlwr('..') &&
  WinAPI::pathExists(fullFileName(_path,fileName)))
  findFiles(fullFileName(_path,fileName), _fileName, _inclSubDir, fileName);
 
  fileName = WinApi::findNextFile(hdl);
  }
 
  WinApi::findClose(hdl);
  }
  }
  }

  findFiles('c:\\Program Files','*.doc');
 }



==============
Источник: http://axgeek.spaces.live.com/Blog/c...DB13!150.entry
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
За это сообщение автора поблагодарили: Gustav (0), alex55 (1).
Старый 08.10.2009, 17:36   #2  
alex55 is offline
alex55
MCTS
MCBMSS
 
224 / 145 (5) +++++
Регистрация: 13.02.2007
Адрес: Москва
А кто-нибудь знает почему возвращаются значения '.' и '..' при обработке пустой директории и зачем в коде берется нижний регистр от точек?
Теги
winapi

 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
Dynamics AX: Managing Your Supply Chain Using Microsoft Dynamics AX 2009 - Book Review Blog bot DAX Blogs 0 31.03.2009 23:06
axStart: Microsoft Dynamics AX 2009 Hot Topics Web Seminar Series Blog bot DAX Blogs 0 06.08.2008 12:05
Inside Dynamics AX 4.0: Usage Scenarios Blog bot DAX Blogs 0 04.10.2007 05:15
Сергей Герасимов: Что нового в Microsoft Dynamics AX 4.0 Blog bot DAX Blogs 0 16.01.2007 11:00
Dynamics AX Geek: Finding files with WinAPI Blog bot DAX Blogs 0 28.10.2006 16:40

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 02:44.
Powered by vBulletin® v3.8.5. Перевод: zCarot
Контактная информация, Реклама.