Solved: Variable as folder name

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

dampyr

Thread Starter
Joined
Nov 25, 2011
Messages
23
Hello,
Every first day of the month,we need to create folder for example:11 Novembar
where 11:Number of month,November name of the month:
Is there way to create variable to automatically change folder name accordingly every first of the month:

12 December
01 January
and so on:

Thanks
 

Squashman

Retired Trusted Advisor
Joined
Apr 4, 2003
Messages
19,786
If you are referring to doing it in a batch file then yes you could. Date is a system variable.
Code:
C:\Users\Squash>echo %date%
Fri 11/25/2011
Now if I want to pull the month from that I would do the following
Code:
C:\Users\Squash>echo %date:~4,2%
11
How the date variable outputs in a batch file is dependent on your Regional and Language settings. So yours may be slightly different than mine but you can adjust the code above accordingly.
 

dampyr

Thread Starter
Joined
Nov 25, 2011
Messages
23
Folder name is in format "11 Novembar" and must be created only 1st day of the month,for example
01.11 11 November
01.12 12 December

...........
 

Squashman

Retired Trusted Advisor
Joined
Apr 4, 2003
Messages
19,786
I don't see the point of creating the month as a numeric value and the Name of the month. If you only need it created the 1st day of the month then use Windows Task Scheduler to only run the batch file the 1st day of the month.

Or if you have an existing batch file use an IF statement to see if it is the 1st day of the month by using the same type of code I posted in my previous post and it if is then create the folder. Of course you will need a bunch of additional IF statements so that you can get your Month Number Month Name format.

I would really need to see your entire batch file to see what is going on to make a better judgment on how to proceed.
 

dampyr

Thread Starter
Joined
Nov 25, 2011
Messages
23
I will provide it tommorow:

What is the point:In folder "11 Novembar",using batch file-automatically,every morning is created folder name
01.11,02.11,03.11,04,11.....In these folders are files copied from network drive.These files are formated,converted to excel and then sent as mail attachments.All this is attained by macros.When next month come,then manually we must create new folder "12 December" in which all files for december are stored and so on.All works automatically except making new folder every month.In existing batch file,on the beginning,is
11 November,so we change it in 12 December,01 January.I will post batch file as soon as possible
 

Squashman

Retired Trusted Advisor
Joined
Apr 4, 2003
Messages
19,786
So you have some other script that is coded to look at the Month as a Numeric Value and Name Vaue. Why not make it easier on yourselves and change that code to just look for the Numeric value of the month.

I am not really understanding your explanation in your last post. I am going to assume that is a language barrier issue. The way you write your sentences tells me that English may not be your first language.

If you could show me the folder structure I may be able to better understand what you are trying to do.
 

dampyr

Thread Starter
Joined
Nov 25, 2011
Messages
23
Yes,english is not my naitive language:
In folder "11 November",every morning is created folder for that date:
on the first of november,folder "01.11" is created using batch,on the second of the november,folder 02.11 is created,and so on...

01.11.2011 C:\Local Data\11 November\01.11\some files
02.11 2011 C:\Local Data\11 November\02.11\some files
30.11 2011 C:\Local Data\11 November\30.11\some files

01.12.2011 C:\Local Data\12 December\01.12\some files
31.12 2011 C:\Local Data\12 December\31.12\some files

01.01.2012 C:\Local Data\01 January\01.01\some files


Only part of the code: "11 November" must be manually renamed every month in batch file (01.12 will be renamed to "12 December") in order for folder "12 December" to be created,and that files for december not end up in folder "11 November".

Sorry,i wasn't made myself clear:batch creates folder "11 November" we ONLY need to change "11 November",on the beginning of the next month to:12 December-manually.
If renaming wouldn't be performed,files for oncoming month would be in folder "11 November"


I want for batch itself to change folder name "11 November" to "12 December"-01.12.2011

I hope that is now more obvious what i want.

Batch file runs every morning (5 AM)

When i post batch file content,everything will be clarified


Folder naming convenction CAN'T be changed-company policy
 

Squashman

Retired Trusted Advisor
Joined
Apr 4, 2003
Messages
19,786
That is really overkill and redundant for your folder names. Why do you do it that way?
If I was doing what you are doing I would be doing it more like this:
C:\source\2011\11\25\
C:\source\2011\11\26\
 

dampyr

Thread Starter
Joined
Nov 25, 2011
Messages
23
Don't ask :(,as i said in previous post,IT policy doesn't allow changing naming policy.



@echo off
:: variables
set drive=C:\Local Data\Liste\11 Novembar\
set hc=HC_data\
set ST42=Uzice
set folder=%date:~0,5%
set broj="0610"+%date:~2,2%+".jdc"
set backupcmd=xcopy /s /c /d /e /h /i /r /k /y
 

Squashman

Retired Trusted Advisor
Joined
Apr 4, 2003
Messages
19,786
See how you are creating a substring variable of the system date variable. You can do the same thing with your drive variable but you will also need to use some IF statements to hard code the month name.

Like I said earlier, the date variable is defined by your regional settings. I would need to see the output of the date variable to get the exact code for you but it could look something like this if the numeric digits for the month are the first characters from the date variable.
Code:
If "%date:~0,2%"=="11" set drive=C:\Locale Data\Liste\11 November\
Now obviously you will need 11 more If statements like that.
 

dampyr

Thread Starter
Joined
Nov 25, 2011
Messages
23
Thank You so much for You effort !!

output for data variable:26.11.2011
 

dampyr

Thread Starter
Joined
Nov 25, 2011
Messages
23
Here is result from other forum:

If you ran this script with a scheduled task at the beginning of every month, it would create the folder you want on the c drive. If you run it right now, it will create a folder named c:\11_November
@echo off
setlocal
set v=%date:~4,2%
set month_num=%date:~4,2%
set month_text=01-January;02-February;03-March;04-April;05-May;06-June;07-July;08-August;09-September;10-October;11-November;12-December
call set v=%%month_text:*%v%-=%%
set v=%v:;=&rem.%
mkdir c:\%month_num%_%v%
endloca
 

Squashman

Retired Trusted Advisor
Joined
Apr 4, 2003
Messages
19,786
Looks like you are good to go then. But instead of having a separate batch file that is scheduled to run on first day of the month you could just put some code into your existing batch file to see if it is the first day of the month and then just create the directory. Either way works. Just depends on what you feel comfortable with.
 

dampyr

Thread Starter
Joined
Nov 25, 2011
Messages
23
I would prefer to put this code in existing batch.I really appreciate Your help.Now i must experiment with this code to see if it works as expected.Once again,thanks a lot!!!.You are a script guru!!!
 

Squashman

Retired Trusted Advisor
Joined
Apr 4, 2003
Messages
19,786
I think this will work for you. I kind of took the same idea of how they were setting up the folder name for the month but I figured I could do it in less code than they did.

Code:
@echo off
:: variables
[color=green]:: setting v to equal the current numeric month[/color]
[color=red]set v=%date:~3,2%[/color]
[color=green]:: putting all the possible months into a variable which will be parsed in the for loop[/color]
[color=red]set month_text="01 January" "02 February" "03 March" "04 April" "05 May" "06 June" "07 July" "08 August" "09 September" "10 October" "11 November" "12 December"[/color]
[color=green]:: for loop is parsing the month_text variable and using the find command with the numeric month to set the current_month variable[/color]
[color=red]for %%I in (%month_text%) do echo %%I |find "%v%" &&set current_month=%%~I
set drive=C:\Local Data\Liste\%current_month%\[/color]
[color=green]:: checking if it is the 1st day of the month and if it is create the new directory.[/color]
[color=red]IF "%date:~0,2%=="01" mkdir "%drive%"[/color]
set hc=HC_data\
set ST42=Uzice
set folder=%date:~0,5%
set broj="0610"+%date:~2,2%+".jdc"
set backupcmd=xcopy /s /c /d /e /h /i /r /k /y
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Top