Hello there,
I am having some troubles creating a batch file...I have searched and searched and made it a little bit of the way on my own and was hoping someone could help me out.
What I am trying to do is as follows:
Search a directory with many sub directories for a certain file type (lets say a .txt file)
If the script finds this file I would like a Folder created called Sample in the directory the .txt file was found
Then move the .txt file to this Sample folder
And if the script finds the file in a folder already named Sample to do nothing and continue on.
I have this as my batch so far and it works in finding the file and moving it to the Sample folder, the only problem is the Sample folder is created in the root of where i ran the batch file and all .txt files found are moved to this folder. Close but not quite right.
________________________________________________
@echo off & setlocal EnableDelayedExpansion
echo.
for /R %%a in (*.txt) Do (
mkdir "Sample"
move %%a "Sample" )
echo.DONE
______________________________________________________________
An example of the directories I am talking about would look like this.....
Folder1/SubFolder1/12345.txt
/SubFolder2/12345.txt
Folder2/SubFolder1/23456.txt
/SubFolder2/Sample/23456.txt
Thanks in advance for your wisdom.
Regards,
Ryan
Batch File Help
Moderator: DosItHelp
Re: Batch File Help
Maybe something like that:
Regards
aGerman
Code: Select all
@echo off &setlocal
for /f "tokens=* delims=" %%i in ('dir /a-d /b /s *.txt^|findstr /v "\\Sample\\"') do (
md "%%~dpiSample" 2>nul
move "%%~i" "%%~dpiSample\"
)
Regards
aGerman
Re: Batch File Help
beautiful...thanks so much!
works perfect.
works perfect.