Batch Name Change Based on Current File Name - batch-file

I have a bunch of files named with the following structure.
BIOSTD_2022-05-11_08-07-29_LastName_FirstInitial_70061643.pdf
The First set of numbers if obviously the date and the second set is the time the file was created. I'd like to batch change the names to the following file structure
LastName_FirstInitial.pdf
and then move it to a new folder with the date in the original file name. There will be multiple files with the same date.
Can anyone help me out?
Thanks
Greg
I really don't know where to start.

Related

How can I find the newest files in a specific folder and all of it's subfolders in a cmd?

I want to keep my database updated, so every time I get the latest files from TFS I want to find the changed files (newest in date) in order to run them and not run ALL of the files.
I want to create a batch file to search, find and copy them to a temp folder so I'll be able to run only them.
A creative solution would be you can enter dir results into a text file and then whichever language you are using just do string slicing which can give u date, memory and name of the file. This is command- dir/a>file replace file with the text file. if u want the text to be entered into the file in append mode then dir/a>>file

How to randomize file order on folders with a batch file

am trying to get a batch file to help me randomize files.
Files are videos/music/text/doc
To be more specific, lets say am having the following files on a folder named like this:
3020_1
3020_2
3020_3
3020_4
3020_5
6031_1
6032_2
5013_1
6060_1
Windows will sort them as above, and i would like to get a folder with the above files to appear randomly.
Can you guys help me out :)
I am sure you are aware of the fact that the order of appearance of files in a Windows folder depends on the sort option you have chosen. Assuming you still want to do this in a given sorted view and you are OK renaming files, you can try the ren command to do this. Find more details here
ren 3020_1 3020_2
Since you want this to be random, you will have to add a bit of logic to get a random file name.
%RANDOM% will give you a random number every time you execute it. More information on that is available here
Hope this gets you move further

Using a batch file to copy multiple files with the same name, and past into new folder with differing names

I have a long list of files that are auto-produced every month. they'll all have the same file name, with a sequential file extension like this:file.001, file.002, file.003
Each file has differing information, despite having the same name. What I need to do is copy them from their home directory and paste them into a new directory with names that reflect their purpose, and as text files, like this: Budget.txt, Expense.txt, Retention.txt
Is it possible to do this with a batch file? I've been unable to find a method that works. Any help would be appreciated.
EDIT: I've tried that solution, and it works as far as it goes. the frustrating thing is that the extensions are not always the same, but always sequentially numbered.

Crontab Creating Files with Dynamic File Names

How can I set the crontab to create, say for example, text files with dynamic file names? What I mean is, for instance, I will set the crontab that a text file will be created every minute in a directory. Then the filename that will be assigned to a text file will be depending on what time of the day it is.
Illustration:
0001.txt
0002.txt
0003.txt
0004.txt
...
and so on and so forth.
(Though the example above does not show text file names of the time of the day, you will get the point)
The date command can be used to get the current date and time in the format you want for the files.
filename="`date +%Y-%m-%d_%H%M.txt`"
echo "File created" > filename
Will, right now for me, create a file named "2011-11-12_0905.txt".

using batch command file copy on daily basis

I need to copy files from one machine to my local disc using batch commands.
My files contain the date in dd-mm-yyyy format. But in case if i am using this:
-%date:/=-%
it is interpreted as "day" and then date which is not really associated with my file name at the source end.
Once I click my bat file it will copy one folder say "xyz dd-mm-yyy" I want to copy only today's folder as on my source machine saved last 7 days folder.
EDIT: my folder name on source machine is Site_info 11-07-2011 and tomorrow one more folder will get added to the same machine with name site_info 12-07-2011. I want to run the bat file machine where it will copy only today's folder.
EDIT2: Thanks for kind support still i am not able to achieve my target.If possible please provide the commands for following situation
My machine path :c:\Documents and Settings\user1\Desktop\SITE_INFO\Site_info 12-07-2011 where Site_info 12-07-2011 will change to site_info 13-07-2011
Source address :- \97.253.72.127\Cdma Site_info\Site_info 12-07-2011 Tomorrow one more folder will get add on this path with dated like \97.253.72.127\Cdma Site_info\Site_info 13-07-2011
If you mean that there's the 'day of week' part preceding the date and you want to get rid of that part, then you'll probably need an additional variable. First you'll cut off the day of week, then replace / with -, like you are already doing. It might be something like this:
…
SET "dateonly=%date:~4%"
SET "dateonly=%dateonly:/=-"
…
COPY \\computer\share\path\whatever-%dateonly%.ext drive:\path\%dateonly%\
…
You could try to puzzle the date the way you want it:
set mydate=%date:~-10,2%-%date:~-7,2%-%date:~-4%
xcopy /E /I "Site_info %mydate%" "Copy\Site_info %mydate%"

Resources