|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Copy files based to different directories based on certain characters in file name
Hi,
I have thousands of files with names in format filename_str1_str2.dat where str1 is some string occurnace in file name. I want to write a dos batch that can read str1 from name of file and based on value copies the file to one of several directories. I cann't find a way to strip str1 from file name. The batch should be able to iterate through all files in directory and copy to destination based on str1. Any help please ? Thanks Moe |
|
#2
|
|||
|
|||
|
You can use a FOR loop to parse a variable into tokens. See the for command help by typing "for /?" into your command line.
You can write a batch file like this: Code:
set FILE=filename_str1_str2.dat
for /f "tokens=1-3 delims=_" %%I in ("%FILE%") do (
echo %%I
echo %%J
echo %%K
echo copy %FILE% %%J
)
Output: Code:
filename str1 str2.dat copy filename_str1_str2.dat str1 you can remove the 'echo' on the 'echo copy' line to get your copy functionality |
![]() |
| Viewing: Web Development Archives > FAQs > MS DOS > Copy files based to different directories based on certain characters in file name |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|