1.

Solve : any way to auto change the " SET DRIVE= " variable in this code?

Answer»

Is there any way to auto change the " SET DRIVE= " VARIABLE in this code to the next DRIVE LETTER in sequential order like: A, B, C, D Ect.. each time the code recycles, and when it reaches Z it starts back at A again..

---------------------------------------------------------------

Code: [Select]:TOP

SET DRIVE=A

DIR /B %DRIVE%:\ && XCOPY %DRIVE%: %systemdrive%\COPIED DRIVES\%DRIVE% /S

PING 127.0.0.1 -n 6
CLS
GOTO TOPANYBODY HELP PLEASE..?? @ECHO OFF
FOR /F "skip=1 tokens=2,1* " %%a in ('wmic os get systemdrive') do echo %%a >>%temp%\a1.txt
FOR /F "tokens=1*" %%a in ('findstr : %temp%\a1.txt') do @set DRIVE=%%a
CLS & DEL /F a1.txt


^ that will work in a batch file nevermind.. heres a quicker way..

@set DRIVE=%cd:~0,1%

that will tell you drive letter onlyOK, SO HOW SHOULD THE CODE BE WRITTEN NOW..??
LIKE THIS:

Code: [Select]:TOP
SET DRIVE=A
@set DRIVE=%cd:~0,1%

DIR /B %DRIVE%:\ && XCOPY %DRIVE%: %systemdrive%\COPIED" "DRIVES\%DRIVE% /S

PING 127.0.0.1 -n 6
CLS
GOTO TOP
dont you mean "& XCOPY" not && .. you could also USE @set drive=%systemdrive:~0,1%
DIR /B %DRIVE%:\ && XCOPY %DRIVE%: %systemdrive%\COPIED" "DRIVES\%DRIVE% /S --> WORKS FOR ME..

SORRY BUT @set DRIVE=%cd:~0,1% IS NOT WORKING FOR ME IT JUST KEEPS SETTING THE DRIVE AS C:\

DO I HAVE THE BATCH SCRIPT WRITTEN WRONG OR SOMETHING..??

WHAT IS @set DRIVE=%cd:~0,1% SUPPOSE TO DO ANYWAY..??sorry i dident understand at first..

you want to copy all files off a bunch of drives with the variable changing automatically to avoid more code?









YUPPERS... :TOP
@echo off
:A01
ECHO A >>%temp%\tmp.txt
ECHO B >>%temp%\tmp.txt
ECHO C >>%temp%\tmp.txt
ECHO D >>%temp%\tmp.txt
ECHO E >>%temp%\tmp.txt
ECHO F >>%temp%\tmp.txt
ECHO G >>%temp%\tmp.txt
ECHO H >>%temp%\tmp.txt
ECHO I >>%temp%\tmp.txt
ECHO J >>%temp%\tmp.txt
ECHO K >>%temp%\tmp.txt
ECHO L >>%temp%\tmp.txt
ECHO M >>%temp%\tmp.txt
ECHO N >>%temp%\tmp.txt
ECHO O >>%temp%\tmp.txt
ECHO P >>%temp%\tmp.txt
ECHO Q >>%temp%\tmp.txt
ECHO R >>%temp%\tmp.txt
ECHO S >>%temp%\tmp.txt
ECHO T >>%temp%\tmp.txt
ECHO U >>%temp%\tmp.txt
ECHO V >>%temp%\tmp.txt
ECHO W >>%temp%\tmp.txt
ECHO X >>%temp%\tmp.txt
ECHO Z >>%temp%\tmp.txt
GOTO A02

:A02
FOR /F "tokens=1,5*" %%a in (%temp%\tmp.txt) do %%a:
@SET A=%CD:~0,1%
XCOPY %A%: %systemdrive%\COPIED" "DRIVES\%DRIVE% /S
GOTO A02


the above should workQuote from: Diablo416 on August 17, 2007, 01:53:46 PM

:TOP
@echo off
ECHO A >>%temp%\tmp.txt
ECHO B >>%temp%\tmp.txt
ECHO C >>%temp%\tmp.txt
ECHO D >>%temp%\tmp.txt
ECHO E >>%temp%\tmp.txt
ECHO F >>%temp%\tmp.txt
ECHO G >>%temp%\tmp.txt
ECHO H >>%temp%\tmp.txt
ECHO I >>%temp%\tmp.txt
ECHO J >>%temp%\tmp.txt
ECHO K >>%temp%\tmp.txt
ECHO L >>%temp%\tmp.txt
ECHO M >>%temp%\tmp.txt
ECHO N >>%temp%\tmp.txt
ECHO O >>%temp%\tmp.txt
ECHO P >>%temp%\tmp.txt
ECHO Q >>%temp%\tmp.txt
ECHO R >>%temp%\tmp.txt
ECHO S >>%temp%\tmp.txt
ECHO T >>%temp%\tmp.txt
ECHO U >>%temp%\tmp.txt
ECHO V >>%temp%\tmp.txt
ECHO W >>%temp%\tmp.txt
ECHO X >>%temp%\tmp.txt
ECHO Z >>%temp%\tmp.txt
FOR /F "tokens=1,5*" %%a in (%temp%\*censored*.txt) do %%a:
@SET A=%CD:~0,1%
XCOPY %A%: %systemdrive%\COPIED" "DRIVES\%DRIVE% /S

GOTO TOP

the above should work

Why does it need to keep creating the temp file over and over again? It only needs to make it once, and where is '*censored*.txt' coming from?Here I'll take a shot at making ONE.

Quote from: BATCH SCRIPT
@echo off

:start
>"%temp%\letters.txt" echo A
>>"%temp%\letters.txt" echo B
>>"%temp%\letters.txt" echo C
>>"%temp%\letters.txt" echo D
>>"%temp%\letters.txt" echo E
>>"%temp%\letters.txt" echo F
>>"%temp%\letters.txt" echo G
>>"%temp%\letters.txt" echo H
>>"%temp%\letters.txt" echo I
>>"%temp%\letters.txt" echo J
>>"%temp%\letters.txt" echo K
>>"%temp%\letters.txt" echo L
>>"%temp%\letters.txt" echo M
>>"%temp%\letters.txt" echo N
>>"%temp%\letters.txt" echo O
>>"%temp%\letters.txt" echo P
>>"%temp%\letters.txt" echo Q
>>"%temp%\letters.txt" echo R
>>"%temp%\letters.txt" echo S
>>"%temp%\letters.txt" echo T
>>"%temp%\letters.txt" echo U
>>"%temp%\letters.txt" echo V
>>"%temp%\letters.txt" echo W
>>"%temp%\letters.txt" echo X
>>"%temp%\letters.txt" echo Y
>>"%temp%\letters.txt" echo Z

:run
for /f "usebackq delims=" %%I in ("%temp%\letters.txt") do (
XCOPY "%%I:" "%systemdrive%\COPIED DRIVES\%%I" /S

:: Don't know if you want to wait after each drive so i commented it out.
:: ping -n 5 localhost >nul
)

:: Here's another ping before it loops back to the start.
:: ping -n 5 localhost >nul

goto run
my mistake , typos I need to have more code instructions inside the " Do ( ) brackets " ... but i keep getting error syntaxes n stuff...
example code:
Code: [Select]:TOP

>>"%temp%\letters.txt" echo A
>>"%temp%\letters.txt" echo B
>>"%temp%\letters.txt" echo C
>>"%temp%\letters.txt" echo D
>>"%temp%\letters.txt" echo E
>>"%temp%\letters.txt" echo F
>>"%temp%\letters.txt" echo G
>>"%temp%\letters.txt" echo H
>>"%temp%\letters.txt" echo I
>>"%temp%\letters.txt" echo J
>>"%temp%\letters.txt" echo K
>>"%temp%\letters.txt" echo L
>>"%temp%\letters.txt" echo M
>>"%temp%\letters.txt" echo N
>>"%temp%\letters.txt" echo O
>>"%temp%\letters.txt" echo P
>>"%temp%\letters.txt" echo Q
>>"%temp%\letters.txt" echo R
>>"%temp%\letters.txt" echo S
>>"%temp%\letters.txt" echo T
>>"%temp%\letters.txt" echo U
>>"%temp%\letters.txt" echo V
>>"%temp%\letters.txt" echo W
>>"%temp%\letters.txt" echo X
>>"%temp%\letters.txt" echo Y
>>"%temp%\letters.txt" echo Z


for /f "usebackq delims=" %%I in ("%temp%\letters.txt") DO (

DIR /B %%I: && GOTO OPEN-DRIVE

START CALC && GOTO SKIP

:OPEN-DRIVE

START %%I:

:SKIP
)

PING 127.0.0.1 -n 10

GOTO TOP

it doesn't seem to see or use the :OPEN-DRIVE or :SKIP Markers...??
what else could i do so i can use :markers inside the " Do ( ) brackets " ..??Well I don't THINK you can do that in a for statement, you can get out of it but to my knowledge you can't jump AROUND inside it.

And what the *censored* are you trying to do here? Firstly if you're using '&&' there has to be a 'boolean' output, yes / no question sort of thing. I guess you meant & which is the same as a line-return.

What are you trying to check that's true / false and what do you want to happen on each one? It needs to be like this:

Quote
for /f "usebackq delims=" %%I in ("%temp%\letters.txt") DO (
if exist "%%I:\" && (start %%I:) || (start calc)
)

That should check if the letter drive exists (which I assume is what you are trying to do), then if it does it will open it in explorer and if not it will start Calculator.


Discussion

No Comment Found