Batch file to move a download to new folder - date

I used the tampermonkey extension to download an excel file every time I visit a certain URL. I want to write a batch file that will visit that URL everyday, cause the file to download, and then move that downloaded file into a new folder.
I know how to get to the url and initiate the download with a batch script
The downloaded filename is in the format "websitename_DDMonYYY," except if the date is 1 digit the leading zero is removed.
For example, today's downloaded file would be "websitename_8Feb2023"
How can I write a script that will match the downloaded file name to today's date, so that I can then move it to a new folder?
I've been trying to use the %date:~#,#% syntax to extract the day, year, and month, but I need help removing the leading zero in the date, converting the month number into a 3 letter code, and then concatenating all of these into a single string.
Thank you!

Related

Azure data factory name output folder as the current timestamp

I am running a copy activity and I am trying to place the output file in a folder that is named after the current the timestamp. I am using utcnow('G') so I get the 10/21/2020 1:30:45PM. But when I run it it puts the file within 3 nested folders like this 10 / 21 / 2020 1:30:45PM/ file. It splits the date to make the month its own folder, the day its own folder within that, and the year and time its own folder within that. I am completely dumbfounded on why this is happening. Obviously I just want a single folder. How do I fix this?
This is because utcnow('G') contains '/'. When you have '/' in your folder path, this means you have sub folder. So you will create three folders:10,21 and 2020 1:30:45PM. If you only want a single folder, you can replace '/' to other character like '-'. Or just use other date format which not contains '/',such as 'utcnow('o')'.More detail,you can refer to utcnow() function https://learn.microsoft.com/en-us/azure/data-factory/control-flow-expression-language-functions#utcnow.

How to move file into another directory which have current date and time stamp (YYYY-MM-DD_HH-MM) in shell

I want to move one file from one folder to another. Another folder is randomly generating with date and time stamp at run time in YYYY-MM-DD_DD-MM format. The code is given below. I need to give path of current timestamp in this YYYY-MM-DD_DD-MM format.
Written Some Code for same
# Command to execute
execute_cmd=mv
path=/home/centos
# Files inside actual_dir has to be moved
actual_dir="$path/Input_File"
# This is the directory where files will be moved and kept
backup_dir="$path/Archive/{$Here I want to write some code so that I can move into one particular folder with date and time stamp YYYY-MM-DD_DD-MM} "

How to remove the file extension using a snippet variable. List of snippet variables

I use vscode.
I want to use costum snippets, but {TM_FILENAME} has an extension name.
How can I delete the extension from {TM_FILENAME}?
like this:`
In file MyModule.js:
Transform: ${TM_FILENAME/(\w+)\.js/\1/g}
Output:
MyModule
You can use TM_FILENAME_BASE to get only the filename:
${TM_FILENAME_BASE}
Actually, since the question was posed a few new built-in variables have been added,
including TM_FILENAME_BASE. See snippet variables documentation. So there is no need to do a transform just to get the filename without the extension.
Here is the current list of snippet variables:
TM_SELECTED_TEXT The currently selected text or the empty string
TM_CURRENT_LINE The contents of the current line
TM_CURRENT_WORD The contents of the word under cursor or the empty string
TM_LINE_INDEX The zero-index based line number
TM_LINE_NUMBER The one-index based line number
TM_FILENAME The filename of the current document
TM_FILENAME_BASE The filename of the current document without its extensions
TM_DIRECTORY The directory of the current document
TM_FILEPATH The full file path of the current document
CLIPBOARD The contents of your clipboard
WORKSPACE_NAME The name of the opened workspace or folder
CURRENT_YEAR The current year
CURRENT_YEAR_SHORT The current year's last two digits
CURRENT_MONTH The month as two digits (example '02')
CURRENT_MONTH_NAME The full name of the month (example 'July')
CURRENT_MONTH_NAME_SHORT The short name of the month (example 'Jul')
CURRENT_DATE The day of the month
CURRENT_DAY_NAME The name of day (example 'Monday')
CURRENT_DAY_NAME_SHORT The short name of the day (example 'Mon')
CURRENT_HOUR The current hour in 24-hour clock format
CURRENT_MINUTE The current minute
CURRENT_SECOND The current second
CURRENT_SECONDS_UNIX The number of seconds since the Unix epoch
For inserting line or block comments, honoring the current language:
BLOCK_COMMENT_START Example output: in PHP /* or in HTML <!--
BLOCK_COMMENT_END Example output: in PHP */ or in HTML -->
LINE_COMMENT Example output: in PHP // or in HTML <!-- -->
vscode v1.66 will add two new variables:
CURSOR_INDEX 0-based
CURSOR_NUMBER 1-based
The above two work with multiple cursors so that each cursor position (same as a selection) will have an incremented integer inserted.
For an example of this, see https://stackoverflow.com/a/69946559/836330
It looks like v1.40 will add:
WORKSPACE_FOLDER Path of workspace directory
RANDOM Insert 6 random digits
RANDOM_HEX Insert 6 random hex digits
See https://github.com/microsoft/vscode/pull/82529 and https://github.com/microsoft/vscode/pull/79764
v1.53 will add the relative path from the root folder to the current file:
RELATIVE_FILEPATH
UUID
See https://github.com/microsoft/vscode/pull/114208 and https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_53.md#new-snippet-variables
You can't do this at the moment but there's a feature request on the vscode GitHub page for what you want: https://github.com/Microsoft/vscode/issues/6920.
[EDIT]
My answer above is now out of date - you can use the ${TM_FILENAME_BASE} variable as mentioned by other contributors.
You can try something like this if you know the file extension,
${TM_FILENAME/(.js)//}
It will turn FileName.js to FileName

Batch: Create a Folder and Name it by Today's Date

How can I make a batch file that will create a folder (in a specified directory) that will create a folder and label it with today's date? Can I also make it delete folders that are one week old or older?
One question at a time. Addressing your first one:
cd \YourSpecificDirectory
SET Today=%Date:~10,4%%Date:~4,2%%Date:~7,2%
REN Creates folder in format 20050812 (depending on regional settings and language)
md %Today%
Answers to your second question (how to delete a folder before a certain date) already exist here. A search should find them for you pretty easily.
Please see this post how to get data value independent of data/Time format (zone):
batch file to copy some files and changing their name

Split Filename Up to Define Variables

I have a script I created to help with converting a video then uploading it to our website. Our videos all have a standard format for their filename to help with setting them up correctly (day, month, year; i.e. 09OCT2013.m4v). They get filed into directories from year to month to day (i.e. 2013/oct/09OCT2013/09OCT2013.m4v). Right now, my script opens by asking for user input for the year then month then the actual file name for the folder. What I want to do is take the file that has already been created, drop it into the script, then have the script take it apart and put it in the appropriate file (i.e. drop the file 12JUN2012.m4v into the script and the script automatically puts it into 2012/jun/12JUN2012/). Is there any possible way to do this in terminal? Please let me know if any part of my question is unclear.
Assuming that you're using bash:
for file in "$#"
do
dd=${file:0:2}
mm=${file:2:3}
yy=${file:5:4}
mv "$file" "$yy/$mm/$file"
done
If the file needs to be moved further, or is supplied with more pathname, you can adjust the script, but the basic idea of splitting the last component of the file name up using the substring notation is good.