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
Related
I'm trying to copy photos from someone's iphone to my windows laptop. The problem is the photos on the iphone save as filename like IMG 360, IMG 361 etc... but this isn't helpful when I want to copy these and organise by a certain filename and date created.
I use Google Photos and my own backup to organise photos in chronological order.
We went on holiday together and I am trying to find the best way to get their files organised and merged in with my own photos so that they appear in the right chronological order.
Unless there is a better way to do this, I am trying to create a file listing using a BAT file to list all the files together with their CREATED DATE and then I will create another BAT file to rename those files by incorporating their CREATED DATE.
Any ideas?
Thanks Chirag
I tried the below but this is supposed to only organise in chronological order, but it doesn't seem to even do that.
dir /a /b /-p /s /T:C /o:gen >filelisting.txt
You can use the command dir /T:C /O:D > filelisting.txt to create a file listing that contains the created date of each file in a directory.
I have a list of files in a adls container which contain date in the name as given below:
TestFile-Name-20221120. csv
TestFile-Name-20221119. csv
TestFile-Name-20221118. csv
and i want to copy files which contain today date only like TestFile-Name-20221120. csv on today and so on.
I've used get metedata activity to get list of files and then for each to iterate over each file and then used set variable to extract name from the file like 20221120 but not sure how to proceed further.
We have something similar running. We check an SFTP folder for the existanc e of files, using the Get Metadata activity. In our case, there can be folders or files. We only want to process files, and very specific ones for that matter (I.e. we have 1 pipeline per filename we can process, as the different filenames would contain different columns/datatypes etc).
Our pipeline looks like this:
Within our Get Metadata component, we basically just filter for the name of the object we want, and we only want files ending in .zip, meaning we added a Filename filter:
:
In your case, the first part would be 'TestFile-Name-', and the second part would be *.csv'.
We then have a For Each loop set up, to process anything (the child items) we retrieved in the Get Metadata step. Within the For Each we defined an If Condition to only process files, and not folders.
In our cases, we use the following expression:
#equals(item().type, 'File')
In your case, you could use something like:
#endsWith(item().name, concat(<variable containing your date>, '.csv'))
Assuming all the file names start with TestFile-Name-,
and you want to copy the data of file with todays date,
use get metadata activity to check if the file exists and the file name can be dynamic like
#concat('TestFile-Name-',utcnow(),'.csv')
Note: you need to fromat utcnow as per the needed format
and if file exists, then proceed for copy else ignore
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.
Good day,
In Kettle Pentaho, if use Move files..., then we can edit the file name in the destination, like specify date time format, so the file like abc.txt will become abc02012015.txt in the destination.
However, in Copy files..., I cant see this option. Anyway to do the same things as Move files...?
You can try "Copy or Move result filenames" Step. Here you can append a date pattern while copying files.
Hope it helps :)
You can check "Destination is file" in Settings in Copy file step and then in "Destination File/Folder" write folder with specify filename
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.