How can I return in for each a directories files/folders without the directory path included?


#1

Hello,
As the topic

variable type - String[]

problem

Thanks


#2

Hi @Marcin,

use

  1. path.getfilename(yourStringfullpath) fro with extension of file.
  2. Path.GetFileNameWithoutExtension(yourStringFullPath) for without extenstion.

try and let me know.

Happy coding
Avi


#3

Hi @Avi7

thanks but there was a problem

that’s why i used Directory.GetDirectories

Thank You for all


#4

@Marcin I think u have created dbNameList variable of array of string change it to string type.


#5

@Manjuts90

I have many files in my folder (path). I must have String[].


#6

@Marcin

  1. Use Directory.Getfiles(“ur folder path”) and assign it string array variable.
  2. Use for each loop input as above array.
  3. Path.GetFileNameWithoutExtension(useloop variable) assign that value to ur required variable.

#7

@Manjuts90

I don’t know if I understood you well, but I hope I did what you wanted:

dbNameList(String[])

(assign) dbNameList = Directory.GetFiles(folder path)

(foreach) item in dbNameList

(Type into)
Path.GetFileNameWithoutExtension(dbNameList)

error
Unfortunately, it receives error - “1-dimensional String []” cannot be converted to “String”
variable type String[]


#8

@Marcin

image

Change the marked variable in pic with item.ToString


#9

THANKS!! @Manjuts90