I am use Command line in my project " for loop copy " not work Folder name contains spaces
Example :
For /r "C:\Users\MyUser\Desktop\New Folder" %i in (*.jpg) do copy %~fi "C:\Users\MyUser\Desktop\New Folder\MyFolder" /Y
"New Folder" have contains spaces , The Command not Work
in New Folder
1.jpg in Folder A
2.jpg in Folder B
I want copy all files *.jpg to MyFolder
1.jpg
2.jpg
Help me please .
Thank you.
Muhammad Imran AnsariPosted Oct 7, 2024, 10:29 AM
Hi Paradorn,
Have you tried the destination path with double quotes? add %~fi in double-quotes, Try this
"%~fi" "C:\Users\MyUser\Desktop\New Folder\MyFolder"
Full Line:
For /r "C:\Users\MyUser\Desktop\New Folder" %i in (*.jpg) do copy "%~fi" "C:\Users\MyUser\Desktop\New Folder\MyFolder" /Y
"%~fi" will ensure that the full path of each found file is treated as a single argument
Thank you.
ParadornPosted Oct 8, 2024, 1:06 AM
Hi
Thank you so much
ParadornPosted Oct 8, 2024, 1:04 AM
Hi ,
Thank you so much
i'm look over it ^^'
Jayraj ChhayaPosted Oct 7, 2024, 11:59 AM
When working with folder names that contain spaces in the command line, it is essential to enclose the entire path in double quotes. In your case, the command should be modified to ensure that both the source and destination paths are correctly quoted.
"C:\Users\MyUser\Desktop\New Folder"is enclosed in quotes to handle spaces.%~fivariable is also enclosed in quotes to ensure that the full file path is correctly interpreted, even if it contains spaces.