sorry about this but this is making me feel dump
I was given this script which is very helpful but for the life of me
I can seem to add a folder
I want to add 2Preparing
folder
No matter what I do the script fails to run
can you help me with this
Thank you
for /F "delims=" %%I in ('dir file.txt /A-D /B /S 2^>nul') do for /L %%J in (1,1,%VariableV%) do copy "%%I" "%%~dpIfile (%%J).txt"
I like this script because I can control the outfile file (1).txt
Work Environment
Main Folder
----2Preparing
| File.txt
Main Folder
----2Preparing
| File (1).txt
| File (2).txt
| File.txt
CodePudding user response:
If you want to run that script on a file in a folder that isn't in the same folder as the batch file, you could do this:
for /F "delims=" %%I in ('dir "path\to\folder\file.txt" /A-D /B /S 2^>nul') do for /L %%J in (1,1,%VariableV%) do copy "%%I" "%%~dpIfile (%%J).txt"
Simply add the relative path from the batch file to the file you want to work on. If you want it to be a bit more smart, you can do this.
set count=0
set "path=path\to\folder"
set file=file
:loop
set count=%count% 1
for /F "delims=" %%I in ('dir "%path%\%file%.txt".txt /A-D /B /S 2^>nul') do for /L %%J in (1,1,%VariableV%) do copy "%%I" "%%~dpIfile (%%J).txt"
if %count%==(however many files you want to process) goto:eof
if %count%==1 (
set "path=path\to\another\folder"
set file=anotherfile
)
goto loop
This will let you make a list of every file and every path to those files you want to edit, and then the program will loop through, preforming each operation however many times you need. It would work the same to past your for command string a bunch of times, and set it up with one for each file too, but this way you only need to debug one command.
CodePudding user response:
OK, I have figured out the reason
Original <br>
for /F "delims=" %%I in ('dir file.txt /A-D /B /S 2^>nul') do for /L %%J in (1,1,%VariableV%) do copy "%%I" "%%~dpIfile (%%J).txt"
Temp 1 Failed <br>
for /F "delims=" %%I in ('dir "2Preparing\file.txt" /A-D /B /S 2^>nul') do for /L %%J in (1,1,%VariableV%) do copy "%%I" "%%~dpIfile (%%J).txt"
Answer <br>
for /F "delims=" %%I in ('dir "%~dp02Preparing\file.txt" /A-D /B /S 2^>nul') do for /L %%J in (1,1,%VariableV%) do copy "%%I" "%%~dpIfile (%%J).txt"