Situation:
I am trying to move files inside a loop to a shell, but my code is not working.
for /D %%F in (*) do (
if "%%F" NEQ "%directoryToPutFilesIn%" (
move /y "%%F" "%directoryToPutFilesIn%"
)
)
After several hours of testing, I realized this because %% F points to a folder, so the file cannot be moved.
Bad solution:
As I did, I confirmed my suspicions by storing the %% F value in another variable and using this variable the next turn to move the file. Please note that subsequent work requires initialization %precedentFile%for the first move.
for /D %%F in (*) do (
move /y "%precedentFile%" "%directoryToPutFilesIn%"
if "%%F" NEQ "%directoryToPutFilesIn%" (
move /y "%%F" "%directoryToPutFilesIn%"
set precedentFile=%%F
)
Problem:
This decision is impractical and does not feel right. Is there a way to adapt my current code to do this, or just another way?
source
share