Compare the varaible & create the folder of that variable

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Crystina89
Posts: 5
Joined: 24 Apr 2013 08:48

Compare the varaible & create the folder of that variable

#1 Post by Crystina89 » 24 Apr 2013 09:11

Gents !!

I need a batch script that first pick the country code from the CSV file named as Country_Code.csv and then make a folder of that country code in this format AMX - <country_code>
e.g. i have one code EGT in the Country_code.csv file so it make a folder of this code as AMX - EGT and if this folder is already exist then that script don't allow me to recreate this folder.

In above script i also want one more thing like if the country code is UK then it always make a folder of this name AMX - ZZZ

Country_Code.csv has these values :

- UK
- US
- EGT

I am in very difficult situation due to this script . :(
Please advise me in this matter.I really appreciate your efforts in advance.

Endoro
Posts: 244
Joined: 27 Mar 2013 01:29
Location: Bozen

Re: Compare the varaible & create the folder of that variabl

#2 Post by Endoro » 24 Apr 2013 09:58

Post the entire "Country_Code.csv".

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Compare the varaible & create the folder of that variabl

#3 Post by foxidrive » 24 Apr 2013 21:43

Crystina89 wrote:Country_Code.csv has these values :

- UK
- US
- EGT


That is not a CSV format. Did you post the file correctly?

Crystina89
Posts: 5
Joined: 24 Apr 2013 08:48

Re: Compare the varaible & create the folder of that variabl

#4 Post by Crystina89 » 24 Apr 2013 23:59

Here is the TEXT file values..

- NOR
- SW
- BE
- US
- UK
- EGT

Yes i didn't put csv values .Can you please assist me in this regard ? Like as i mentioned above that i have to create folder of that country code .

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Compare the varaible & create the folder of that variabl

#5 Post by foxidrive » 25 Apr 2013 00:20

Try this. It assumes that the minus sign and space you showed is included in the "- code" on every line.

Code: Select all

@echo off
set "folder=C:\Batch\Script\ABC\CSVSPOOL\TEST"
for /f "delims=" %%a in (Country_Code.csv) do (
if /i "%%a"=="- UK" (
md "%folder%\AMX - ZZZ" 2>nul
) else (
md "%folder%\AMX %%a" 2>nul
)
)

Crystina89
Posts: 5
Joined: 24 Apr 2013 08:48

Re: Compare the varaible & create the folder of that variabl

#6 Post by Crystina89 » 25 Apr 2013 00:41

Hey what if - i want this new folder should be create under the predefined path that is for example i have already defined the path like

@echo off
set LOCATION = C:\Batch\Script\ABC\CSVSPOOL\TEST

Now that new hard coded folder should create under TEST folder .In this case what should i do ?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Compare the varaible & create the folder of that variabl

#7 Post by foxidrive » 25 Apr 2013 00:51

I edited my post above to add that.

Crystina89
Posts: 5
Joined: 24 Apr 2013 08:48

Re: Compare the varaible & create the folder of that variabl

#8 Post by Crystina89 » 25 Apr 2013 01:10

Do you think the below code is correct or make any sense ??Actually i cant try this code multiple times as i am doing work on PROD environment :(

@echo off
set folder = C:\Batch\Script\ABC\CSVSPOOL\TEST

REM Get Names of Affiliates to process from txt file
for /f "tokens=*" %%a in ('type Country_Code.txt') do (

set code=%%a
REM SET code=!code: =!
SET code=!code:-=!
echo Country Name : !code!

For /f "delims=" %%a in ('type Country_Code.txt') do (
IF /i "%%a"=="- UK" (
md "%folder%\AMX - ZZZ\Source Files\" 2>nul
) else (
GOTO : EXIST
)
)

echo Look for path : "AMX - %%a\Source Files\"
IF NOT EXIST "%folder%\AMX - %%a\Source Files\" (
echo Path Does not exist
echo .
)
: EXIST

IF EXIST "%folder%\AMX - %%a\Source Files\" (
echo Path exists

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Compare the varaible & create the folder of that variabl

#9 Post by foxidrive » 25 Apr 2013 02:08

I'd like to see a 'Thank You' and a message saying if it worked for you.

It should do what you asked for, given the information you provided.

Crystina89
Posts: 5
Joined: 24 Apr 2013 08:48

Re: Compare the varaible & create the folder of that variabl

#10 Post by Crystina89 » 25 Apr 2013 02:14

hahhahha.. :D

Thank you so much for your quick help and guidance.

Cheers !! :)

Post Reply