fertlux.blogg.se

Windows mass rename based on timestamp
Windows mass rename based on timestamp






However, we can use it to create a directory (the folder) of the day, like with the command: MD %ClamVirDir%\%today% Our demo batch file is just printed this on the screen with ECHO command. In our example, we collected 27 th day of the 5 th month of the year 2016 in the string with value of 20160527. We just need to write other variables one behind other and the batch interpreter will collect (concatenate) their values in one unique string. We can do that with following command: set today=%year%%month%%day% We will now collect all three separated values together and then we can form forth variable TODAY. Eventually we have three new variables for every element of the today date. When we collect all this together, we will have :~7,2 as the marker for a beginning and the end of the selection. In our example it’s 2, as we need to extract just 7 th and 8 th character in the string. With second value we will indicate length of the substring. We will indicate position of first character with value of X. The x and y are number position and length. We can add :~x,y behind variable name, inside % signs, to tell the batch interpreter that we want just the part of the value, not whole variable value. It’s on 8 th character in the string and that’s position 7. Also, we counted position of that information. Now we need just part of this output (the date string) for out variable named DAY. In our first example we saw that we can display a current day with command ECHO %date% We will analyze further first line: set day=%date:~7,2% Main part of this batch is done in the first three lines beginning with the command SET. I made another batch file, named get_today_date.bat, which will demonstrate this operation. Now that we know what we need to extract, we can use this to write our batch file.

  • And two characters between positions 7 and 8 for a day.
  • Two characters between positions 4 and 5 for a month.
  • Four characters between positions 10 and 13 for a year value.
  • When we analyze this date string, we will see that we need to extract: Furthermore, we can easily find any e-mail held in the quarantine and check it further. We can now see when we caught some viruses in an e-mail. Here is an example of the folders (the ClamAV quarantine folder) sorted by date in their name: When we add the date string in such order, we can later sort the files and folders in ascending order, the day after day, in the chronological order. Then we can use it to create the directory per day or we can add it to the end of the file, like some log or the output result files. That string should be in format YYYYMMDD. We will then repack that information to one string for a today date. We can see that we have also slash sign (/) as the separator. As we can see, we have three letter abbreviation of the name of the day, then we have space, the number of the month in the year, the number of the day in the month and finally the year by the Gregorian calendar. We will continue with first example, the US date format. This is the reason why we begin with 0 in the counter. First character in this string have a position of 0.

    windows mass rename based on timestamp

    We don’t need to count manually positions. Those numbers under the date string will be the position counter. I changed short date format to display the date on the way more common to the Serbian local settings. Here is another example of the changed local settings.

    windows mass rename based on timestamp

    When we run this batch file from the command prompt, we will see current date. Here is source of the check_date_format.bat file: off Those numbers will be used to mark a position of every number or the letter in the date string. I made a simple batch script that will just return the current date and under it write some numbers.

    #Windows mass rename based on timestamp windows

    I used all those scripts on the Windows XP, 2003 Server and later versions of the Microsoft Windows operating systems. With this method you will always have the same format of the current day or time, regardless the local regional settings.

    windows mass rename based on timestamp

    (Update ) You can find the alternate way to read the current date and time values in this post. That’s the reason why we need to check this settings before we can use any batch file that utilize the date value. Therefore, our batch file will work fine with one settings and return useless information with other. The batch files can use special variable named DATE and which returns the current date in the local regional format.Īs we knew, the regional settings are different. We can use the value of current date (and also time) in the batch files, whenever we generating new files and folders. We can use, for example, the dates to distinguish the log files by the days. Using current date as part of the file or a folder (the directory) name is very useful.






    Windows mass rename based on timestamp