I’m using this simple C code:
char * command = NULL;
sprintf (command, "ls %s", folderpath);
system(command);
The problem is when the folder name has a space in it…
I know that in Unix I need to add a “\”, for example ls my\ folder\ name
How can I get around this ? Thank you!
Simple way out is to put the folder name inside single quotes –
sprintf( command, "ls '%s'", folder );. Watch out for command injection as @ndim reminds us.