AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

retrieve the number of files in a folder

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
retrievea
Guest





PostPosted: Thu Apr 19, 2007 10:28 am    Post subject: retrieve the number of files in a folder Reply with quote

Sorry to ask something so basic....
how to retrieve the number of files in a folder?
Code:
dir = c:\pasda
FileRead Filex, %dir%
StringReplace Filex, Filex, `n, `n, All UseErrorLevel
MsgBox Total number of lines is %ErrorLevel%

Thanks in advance.
Back to top
BoBo
Guest





PostPosted: Thu Apr 19, 2007 10:33 am    Post subject: Reply with quote

Code:
Folder = c:\myfolder

Loop, %Folder%\*.*
   NumFiles++
MsgBox %NumFiles% files in %Folder%
Not tested.
Back to top
toralf



Joined: 31 Jan 2005
Posts: 3842
Location: Bremen, Germany

PostPosted: Thu Apr 19, 2007 10:33 am    Post subject: Reply with quote

AFAIK, you need to loop,Filepattern through the path and count. I do not know a shorter way.

Edit: Hi Bobo.
_________________
Ciao
toralf
Back to top
View user's profile Send private message Send e-mail Visit poster's website
BoBo
Guest





PostPosted: Thu Apr 19, 2007 10:36 am    Post subject: Reply with quote

Hi Toralf (Meister deutscher AHKHardcoreProjekte) Wink
Back to top
retrievea
Guest





PostPosted: Thu Apr 19, 2007 11:06 am    Post subject: Reply with quote

Thank you very much! Smile
Back to top
Markus M.



Joined: 17 Apr 2007
Posts: 14
Location: Stuttgart (Ger)

PostPosted: Thu Apr 19, 2007 11:41 am    Post subject: Reply with quote

this one reads the dir recursive, counting files folders and size:
Code:

#NoEnv
SendMode Input

gui,add,text,, Please wait...
Gui, Show,w220 h50 ,Please wait

source=%A_WinDir%
SetBatchLines, -1
Loop, %source%\*, 1, 1
{

  IfInString, A_LoopFileAttrib, D
    NumDirs += 1
  else
    NumFiles += 1

  FolderSize += %A_LoopFileSize%
 
}

gui,destroy

Gui, Add, Text, xm y+20 , Files:
Gui, Add, Text, xp+80  w60 , %NumFiles%
Gui, Add, Text, xs, Directories:
Gui, Add, Text, xp+80  w60 , %NumDirs%
Gui, Add, Text, xm, Size:
SizeMB := Round(FolderSize/1000000 , 2)
Gui, Add, Text, xp+80  w60 , %SizeMB% MB



Gui, Add, Button, gButtonEND Default w100 , Close

Gui, Show, ,Dir content
 
return

ButtonEND:
guiescape:
GuiClose:
ExitApp


this is part of a script i working on

Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group