Remove spaces from file name

Hello, my robot is looping through files in a folder and I would like it to remove spaces from the file name, how can I do this?

Hi @sullivanne

Use the below syntax:

CurrentFile.Name.Replace(" ","")

Hope it helps!!

1 Like

Hi @sullivanne

Path.GetFileNameWithoutExtension(CurrentFile.ToString).Replace(" ", "")

Regards,

1 Like

Thank You, but robot removed spaces in variable but not in folder.

You need to use rename file activity @sullivanne

Regards,

Use Rename File Activity @sullivanne

Regards

Hi,

Maybe something like this.

Path.GetFullPath(YourFilePath).Replace(" ","")

@sullivanne

Path.GetFileNameWithoutExtension(CurrentFile.ToString).Replace(" ", "")

Regards,

I have error: The source doesn’t exist :frowning:

@sullivanne

Can you show the screenshot of workflow

Regards,


The image depicts a flowchart of a file handling process, featuring conditional checks, variable assignments, and file renaming operations. (Captioned by AI)

@sullivanne

Can you please print the currentItem in immediate panel or message box activity

Regards,

A message box displays a file path: "Z:ystrybucja masowaracownik9166_20240901.pdf" with an OK button. (Captioned by AI)
Thank You.

@sullivanne,

Use this in Rename File activity.

Path.GetDirectoryName(currentItem)+"\"+Path.GetFileNameWithoutExtension(currentItem).ToString.Replace(" ","")

This should remove the file name spaces.

Thanks,
Ashok :slight_smile: