0

I'm trying to clean up a few file shares, and I have the list of folders I'm trying to move in a CSV file.

values in delfromtest.csv are

Test1
Test2
test3

I'm attempting to use this.

FOR /F "tokens=1" %%A IN (C:\delfromtest.csv) DO (
if EXIST %Drive%:\%%~A (set asset=%%~A%) 
move "%drive%:\images%drive%\%asset%" "%drive%:\images%drive%\Do not Migrate%drive%\%asset%"
)

this outputs

move "v:\imagesv\C:\delfromtest.csv" "v:\imagesv\Do not Migratev\C:\delfromtest.csv"

but if I remove the entire move command from the loop, the variables are output as desired.

aschipfl
  • 33,626
  • 12
  • 54
  • 99
  • that smells very much like the [delayed expanison trap](http://stackoverflow.com/a/30284028/2152082) (`asset`). And there is a `%` too much. Should be: `(set asset=%%~A)` - except you want the `%` to be part of the value) – Stephan Sep 30 '15 at 14:11

1 Answers1

0

try for without quotes or use usebackq. Enable delayedexpansion when variable is set from and within for

@echo off
setlocal enabledelayedexpansion
for /f %%a in (C:\delfromtest.csv) do ( set asset=%%~a
  if exist %Drive%:\!asset! (
    echo move "%drive%:\images%drive%\!asset!" "%drive%:\images%drive%\Do not Migrate%drive%\!asset!"
  )
)
exit /b 0
Paul
  • 2,620
  • 2
  • 17
  • 27
  • `echo move` should be just `move`, probably a leftover from testing. This comment is just a reminder, I'll remove it in a day. – wOxxOm Sep 29 '15 at 23:12