1.

Solve : Help with Batch Variables!?

Answer»

I am really new to batch commands and self taught...but not very well. What I am looking to do is move one file (*_%var%.csv) from one folder to another, then I would like to remove the original file:

@echo off

set /p var=What is the trigger processing date(yyyy-dd-mm):
echo xcopy C:\LHW Batch Test\*_%var%.csv C:\LHW Batch Test\step4 /y

echo del *_%var%.csv

What am I overlooking?

Thanks!Quote from: skohn

What am I overlooking?

Quotes around path/filenames containing spaces?





Quote from: Salmon Trout on NOVEMBER 24, 2009, 01:47:15 PM
Quotes around path/filenames containing spaces?







I have tried that with no success...so what exactly is happening?
Right now nothing:

C:\Documents and Settings\kohs01\Desktop>test -- I am kicking the batch off here
What is the trigger processing date(yyyy-dd-mm):2009-22-11 --Then I put the user variable that I want
xcopy "C:\LHW Batch Test\*_2009-22-11.csv" "C:\LHW Batch Test\step4" /y --The batch spits out this line
del *_2009-22-11.csv --And this line

And that is itso the files don't get copied nor do they get deleted? (That is what I meant) They exist in the source folder?

Are you sure the date format is not yyyy-mm-dd?



Quote from: Salmon Trout on November 24, 2009, 02:42:49 PM
so the files don't get copied nor do they get deleted? (That is what I meant) They exist in the source folder?

Are you sure the date format is not yyyy-mm-dd?


That is correct the files are not copied or deleted. They are still in the source folder. I am certain that the date format is yyyy-dd-mm...4584136_TRIGGER1_SLPYR_2009-22-11.CSV
It might be case-sensative. Try replacing .csv in your CODE with .CSV Quote from: Helpmeh on November 24, 2009, 03:03:56 PM
It might be case-sensative. Try replacing .csv in your code with .CSV

I have tried that, thank though!I believe I have spotted the problem. The batch is working correctly. However it does not do what skohn expects.

It is staring us in the face:

Quote
xcopy "C:\LHW Batch Test\*_2009-22-11.csv" "C:\LHW Batch Test\step4" /y --The batch spits out this line
del *_2009-22-11.csv --And this line

@echo off

set /p var=What is the trigger processing date(yyyy-dd-mm):
echo xcopy C:\LHW Batch Test\*_%var%.csv C:\LHW Batch Test\step4 /y

echo del *_%var%.csvThat makes me feel like an idiot. Good job pointing that out!skorn, here is an explanation of why the code you posted does not do what you expected it to do. I guess that you found the code somewhere on the web and copied it?

Anyhow, when people post example code that, when run, could do something to your data that you can't undo like moving or deleting files, quite often they put the 'echo' keyword at the beginning of each line where the actions take place.

The point of this is that when the batch file gets to those lines, INSTEAD of performing the command with the variables expanded, instead it echoes the full command line to the screen. This is so you can run the code in 'trial mode', read these lines, consider them, and be quite sure that the batch script will do what you want it to. THis is a good habit to use yourself when trying out code.

When you are happy, you are supposed to delete the 'echo' statements and run the code for real. Usually this is made clear by the author of the code.

I am pretty sure that you will need to use quotes around the paths with spaces.

Personally I would make a test run on a copy of your data to be sure that EVERYTHING is how you want it.

So your code might look like this

Code: [Select]
@echo off

set /p var=What is the trigger processing date(yyyy-dd-mm):
xcopy "C:\LHW Batch Test\*_%var%.csv" "C:\LHW Batch Test\step4" /y

del "*_%var%.csv"

I see what you are saying. I did use an example that I found to guide me. Makes a lot of sense why my results were posting what they were. Thank you so much for the insight...this will definitely help me grow my SKILLS.


Discussion

No Comment Found