batch script to find a particular folder in a drive - batch-file

am a newbie to the batch script, i have many folders called LIB in my drive
say it can be as LIB_data,lib,lib_ac anything that starts with lib or LIB... i want to list all these directories and sort them in which they have created in the pc and copy the latest directory contents to BATCH_LATEST_LIB_FILES folder,that will be a new folder created by this batch file.i want this new folder to be created in the path where this batch file is present. please help me with a batch script.

You might look at FOR, DATE, TIME, SORT, IF, GOTO and XCOPY.
This site is a great resource for batch files.

Related

Using command to find DIR name within USER folder

Im creating a .bat file to copy over a folder from the current directory into the USERS/???/AppData/Local/CourseWork/ folder
However there is no way of knowing what the name of the ??? folder will be as it will be a random students computer.
Is there any way Using Command (and my BAT file) To either retrieve said Folder name , Or copy the files into the Coursework Folder without knowing the ??? folder name.
i was hoping it would be as simple as
copy "Test.exe" "C:\USERS\ . \APPDATA\LOCAL\test.exe"
but unfortunatly it is not.
Iv also looked at Xcopy and robocopy but found no solution , not that there is no solution, i just have not yet found it...
Does anybody have any idea how they would work around this
My .bat file works fine for 1 set of folders & files but once it comes time for this particular folder (C:/USERS/???/APPDATA/LOCAL/COURSEWORK/), im very stuck on what to do for not knowing the name of the ??? folder or how to use Command to copy into the Coursework folder whilst bypassing the name of ???
Thanks for any help.
If the .bat file script is run when the user is logged in, then it is simple.
COPY ".\Test.exe" "%USERPROFILE%\AppData\Local"
If the .bat file script is run while logged in as a different user (ie. "teacher"), then the username must be known AND the "teacher" account must have permission to write into the user's directories.

Ideas for cmd to delete content of documents folder WIN 10?

I want to create a .bat file with a command line inside that deletes all content of the C:\Users\Documents folder. I only want to delete the entire content of the folder, not the folder itself.
Why do I need this? Our company helps unemployed people find jobs and they use our laptops to create CVs and application lettres. They forget to delete their data (most of them don't really know how to use a computer) so I am trying to automate this process with a .bat file and a scheduled task (run script when user logs in).
If the laptops were WIN10 Pro, I would have used group policies in AD, but these computers are WIN10 home.
Any Ideas? Thank you for your help.
One other way to do it is to copy an empty directory using robocopy to the documents folder. So as an example, Create a directory called none.
In this example, I created the empty directory as D:\none
robocopy "D:\none" "%userprofile%\Documents" /MIR
This will work from cmd and in a batch-file.

Batch Programming - Not deleting partial files being written

I am trying to develop a batch script which copies a list of files from the a source directory to another directory and does some functions. Once the copy has been done, the files needs to be deleted from the source directory.
In the source directory, we are receiving files on real time basis 24x7 from an external source.
How can I make sure, the copy or the delete from the script does not impact any files which are currently being sent (incomplete files which are in relay at that moment) from the external source in the source directory, whilst the script is doing its own job?
The script needs to be ran every 5 minutes.
Due to some challenges, we cannot xxcopy for our functionality.
Please can you advise.
Instead of COPY& DELETE use MOVE, so the batch fragment would look like this:
FOR %%F IN (C:\SOURCE\*.*) DO MOVE %%F C:\TARGET\
If file in incomplete (other process uses it), then MOVE on that file will fail. Next time the script is run, it will attempt to move that file again.

Batch File Rename - Batch File needs to move from folder to folder

New to batch file writing. We are unable to install a file renamer program at work so i am looking to find a way to create a batch file to do the job instead. I want to create a batch file that i can place in a folder and it will rename all files in that folder with a prefix, while deleting some text from the file name itself. I am happy to edit the prefix text (as it changes all the time) in Notepad each time but I need to be able to move the batch file to the different folders.
The files will be something like this RDS_117856.pdf
and they need to read as xxx-xxx-xxx-117856.pdf
Any help would be great.
I am using windows, only have access to Notepad and no other coding software so a .BAT file would be the easiest thing to create here.

Create a batch file to update an exe file over FTP

I need to update an exe file on a daily basis, did create a batch file and used the 'fc' command which worked like a charm but i have two issues.
1) The newer version of the exe file would be located on an FTP site
2) The location of the older exe file would not be fixed.
The older exe file is a single executable and the problem is the user can save it anywhere, need a command so that i can locate that file compare it with the file on the FTP site and update that file if needed.
I am new to this, any help is greatly appreciated.
well you can avoid all of this by using a briefcase then put the file that you want to update into the briefcase and then run the update manually.
but if you really want to do it with a batch file then
#echo off
cls
replace (file being updated) (updated file)
exit

Resources