Jump to content

Read name of folders


---
 Share

Recommended Posts

---
Hi guys,

i need a way to read the names of many folders in a directory and i want to use these names with inquireList() to select the needed part.
Kind of inquireList(allFoldersInPath "C:....")

I hope for good ideas 🙂
Link to comment
Share on other sites

---
Hello Michael,

So, I will admit I am still very much a beginner in PCM, but I have done some... interesting things combining it with "systemCall" to run batch files. I'm only going to give this as an outline, but I have gotten it to work on my end.

First, make a batch file. I had to save this in the inspection plan folder for it to work properly for me, likely due to system security. All the batch file does is change the directory to the where ever I want to list the folders from and then use "dir" to list them out to file (that line of code will look a bit like "dir /A:D /B > list.txt", but it will depend a bit on what you need).

I did my testing in the presettings, but again it depends on your specific needs. I used "systemCallWithWait" to call the batch file and wait for the file to be made, then I created a variable "test" and set that equal to the result of "readListFile" of the file I made with the batch file. From there you can use the list in display or whatever you need. The PCM looked a little like what is below:

systemCallWithWait("*PathToInspectionPlan*\FileList.bat")
test = readListFile("*ListLocation*")
display(test)

I hope you find this helpful.
Link to comment
Share on other sites

---
Here is one possibility to return all subfolders in a directory

dir="C:\Users\Client\Documents"
dirContent = dir.asFilename.directoryContentsAsFilenames

for i = 1 to dirContent.size
	if getParameterNamed(dirContent,i).isDirectory
		display(getParameterNamed(dirContent,i))
	endif
next i

Link to comment
Share on other sites

  • 2 weeks later...
---
Die Befehele für das CMD Fenster können auch direkt in den systemCall eingebaut werden.


Code ist nicht getestet. Aber so in etwa müsste es funktionieren

Verzeichnis="C:\temp"
ListFile="liste.txt"
systemCallWithWait("CMD /C dir "+qm()+Verzeichnis+qm()+" /A:D /B>"+ListFile)
readListFile(Verzeichnis+"\"+ListFile)
Link to comment
Share on other sites

---

Please sign in to view this quote.

Deutsche Benutzer sollten das ggf. als Batchdatei aufrufen und darin noch den Befehl 'chcp 1252' voranstellen, damit Umlaute richtig dargestellt werden.
Link to comment
Share on other sites

 Share

×
×
  • Create New...