copy files from uncertain subfolders into another location
Moderator: DosItHelp
copy files from uncertain subfolders into another location
Hi,
I need to copy all files which sit from one subfolder to another location. The issue is that I do not know how many subfolder levels under one known folder (efg) downtwards to this final subfolder, which shall have files with extension .S3S, this final subfolder name can vary depend on different naming convertion...
For examples, I have some files sit in C:\abc\efg\...\1.S3S
C:\abc\efg\...\2.S3S
C:\abc\efg\...\3.S3S
C:\abc\efg\...\4.S3S
C:\abc\efg\...\5.S3S
I need to copy to C:\target folder\
Thanks
I need to copy all files which sit from one subfolder to another location. The issue is that I do not know how many subfolder levels under one known folder (efg) downtwards to this final subfolder, which shall have files with extension .S3S, this final subfolder name can vary depend on different naming convertion...
For examples, I have some files sit in C:\abc\efg\...\1.S3S
C:\abc\efg\...\2.S3S
C:\abc\efg\...\3.S3S
C:\abc\efg\...\4.S3S
C:\abc\efg\...\5.S3S
I need to copy to C:\target folder\
Thanks
Re: copy files from uncertain subfolders into another location
Use DIR with options /B /S in a FOR /F loop or directly a FOR /R loop to iterate recursively across the folder structure.
Steffen
Steffen
Re: copy files from uncertain subfolders into another location
And you were shown how to do both of these concepts in two of your previous threads.
viewtopic.php?f=3&t=8100&p=53824#p53829
viewtopic.php?f=3&t=8715&p=57432#p57433
viewtopic.php?f=3&t=8100&p=53824#p53829
viewtopic.php?f=3&t=8715&p=57432#p57433
Re: copy files from uncertain subfolders into another location
Thank you both!!!
I tried this as below and works
But I was not able to do the same as below:
Thanks
I tried this as below and works
Code: Select all
call C:\auto_pkg_build\Scripts\single_comp\srcfg.cmd
cd "C:\auto_pkg_build\Sources\Source_schemes\Tetra_Schemes\%VARSRC5%-*\%VARSRC5%"
FOR /F "delims=" %%G IN ('dir /b /s *.S3S') DO (
copy %%G C:\auto_pkg_build\Sources\Source_schemes\Single_Replace\%VARSRC1%\
)
Code: Select all
call C:\auto_pkg_build\Scripts\single_comp\srcfg.cmd
cd "C:\auto_pkg_build\Sources\Source_schemes\Tetra_Schemes\%VARSRC5%-*\%VARSRC5%"
FOR /R %%G IN (*.S3S) DO IF EXIST "%%~dpnG" copy "%%~dpnG" C:\auto_pkg_build\Sources\Source_schemes\Single_Replace\%VARSRC1%\
Re: copy files from uncertain subfolders into another location
What do you think are the modifiers ~dpn for?
Steffen
Steffen
Re: copy files from uncertain subfolders into another location
~dpn expands
C:\bla\blub.txt
to
C:\bla\blub
A few more questions to you:
1) Will the file be found if the file extension was stripped from the file name?
2) What is the difference between the content of %%G in the FOR /F loop and the content of %%G in the FOR /R loop?
Steffen
C:\bla\blub.txt
to
C:\bla\blub
A few more questions to you:
1) Will the file be found if the file extension was stripped from the file name?
2) What is the difference between the content of %%G in the FOR /F loop and the content of %%G in the FOR /R loop?
Steffen
Re: copy files from uncertain subfolders into another location
FOR /F - Loop through items in a text fileaGerman wrote: ↑08 Aug 2018 13:52~dpn expands
C:\bla\blub.txt
to
C:\bla\blub
A few more questions to you:
1) Will the file be found if the file extension was stripped from the file name?
2) What is the difference between the content of %%G in the FOR /F loop and the content of %%G in the FOR /R loop?
Steffen
FOR /R - Loop through files (recurse subfolders)
Re: copy files from uncertain subfolders into another location
Not in your case. And you didn't answer my question of what you'll find in %%G. (hint: ECHO %%G helps to figure it out)
FWIW FOR /F processes streams. That can be file streams besides of the standard output stream or string streams. In your example the standard output stream of the DIR command will be processed. No text file is involved.
Steffen
Re: copy files from uncertain subfolders into another location
You are right, there is another one foraGerman wrote: ↑09 Aug 2018 07:39Not in your case. And you didn't answer my question of what you'll find in %%G. (hint: ECHO %%G helps to figure it out)
FWIW FOR /F processes streams. That can be file streams besides of the standard output stream or string streams. In your example the standard output stream of the DIR command will be processed. No text file is involved.
Steffen
FOR /F - Loop through the output of a command
Thanks a lot!