Old 4th January 2018, 09:03   #1
Coby
Junior Member
 
Join Date: Feb 2016
Posts: 48
How can I determine how many files I am in a folder?

Hello!
I used the Call SearchFiles method but the result was not the one I wanted.
E.g:
When I searched files from two different folders,
The first folder resulted in a certain number of files and the second one continued the remaining count in the first folder.
How can I determine the exact number of files for each folder.

PHP Code:
Name "Search File or Folder"
OutFile "SearchFile.exe"

Function SearchFile

  Pop 
$1
  Pop 
$0

  StrCpy 
$$1 1 -1
  StrCmp 
$+2
  StrCpy 
$$-1

  StrCpy 
$$0 1 -1
  StrCmp 
$\ +2
  StrCpy 
$"$0\"

  FindFirst $2 $3 "
$0$1"

FindNextFile:

  StrCmp $3 "" NoFiles
  StrCpy $5 "
$5$0$3|"
  IntOp $4 $4 + 1

  DetailPrint "
$4ş found file: $0$3"

  FindNext $2 $3
  Goto FindNextFile

  NoFiles:

  FindClose $2

  FindFirst $2 $3 "
$0*."

  Push $6

  StrCpy $6 $0 "" 1
  StrCmp $6 "
:\" +2

  FindNext $2 $3

  Pop $6

FindNextSubfolder:

  FindNext $2 $3
  StrCmp $3 "" NoSubfolders

  IfFileExists "
$0$3\" FindNextSubfolder

  Push $0
  Push $1
  Push $2
  Push $3

  Push "
$0$3\"
  Push $1
  Call SearchFile

  Pop $3
  Pop $2
  Pop $1
  Pop $0

  IntOp $4 $4 + 
$R0

  Goto FindNextSubfolder

NoSubfolders:

  FindClose $2

FunctionEnd

var /GLOBAL LOGDIR

Section SearchFile

  Strcpy 
$LOGDIR "$EXEDIR\Log"
  CreateDirectory "
$LOGDIR"

  FileOpen $0 "
$LOGDIR\Log.ini" w
  FileWrite $0 "
[Log]"
  FileClose $0

  Push "
c:\"
  Push "
Temp\*.*"
  Call SearchFile

  Strcpy 
$LOGDIR "$EXEDIR\Log"
  WriteINIStr "
$LOGDIR\Log.ini" "Log" "Temp_Files" "Total Files: $$5"

  Push "
c:\"
  Push "
Google\*.*"
  Call SearchFile

  Strcpy 
$LOGDIR "$EXEDIR\Log"
  WriteINIStr "
$LOGDIR\Log.ini" "Log" "Google_Files" "Total Files: $$5"

SectionEnd 
Coby is offline   Reply With Quote
Old 4th January 2018, 11:45   #2
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,839
Just set $4 to 0 between the calls to SearchFile?

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 4th January 2018, 14:03   #3
Coby
Junior Member
 
Join Date: Feb 2016
Posts: 48
We have not set anything between search requests.
Between these calls is only DetailPrint "$4"
Coby is offline   Reply With Quote
Old 4th January 2018, 16:25   #4
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,839
You call SearchFile two times in a section so it is unclear to me if you are talking about those two or just the recursion inside SearchFile.

If it is inside SearchFile that is the problem then you should code it like this
Quote:
Function SearchFile
StrCpy $4 0
....
;Recurse:
Push $4
Call ${__FUNCTION__}
Pop $4

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 5th January 2018, 09:41   #5
Coby
Junior Member
 
Join Date: Feb 2016
Posts: 48
Thanks Anders
The problem has been solved.
The Call SearchFile function is correct
You just need to set StrCpy $4 0 between the two searches
Coby is offline   Reply With Quote
Reply
Go Back   Winamp & SHOUTcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump