batch script to find last two days from the current date - windows

I am in a project where I need to find all files which are two days lesser than the current date. How can we achieve this using a batch script in Windows?
Appreciate your help!

I have previously misunderstood the question. Here is the updated answer.
The syntax is a little bit different for different OS.
forfiles /d +2 (Windows Server 2008)
forfiles -d+2 (Windows 2000)
In case there is no such command in your OS, here is a link for downloading the FORFILES command.
You can even specify what you want to do for those files. Type forfiles /? or forfiles -? for help.

Not sure what you want to do with the files after you have found them but you could use the ForFiles command.

Related

How do I rename a file to the same name as the folder it is in?

I found similar questions, but to be honest it's all way over my head, and also not exactly what I want.
So, I have over 300 folders that are named, example:
Superstuff/notsuperstuff.jpeg
Othername/notothername.jpeg
randomwords/notrandomwords.jpeg.
I would like the Jpegs to be renamed as the folder. so:
Superstuff/Superstuff.jpeg etc...
btw, I'm using Windows 7, I think batch scripting could do this? Not sure.
Thanks in advance everyone!!
Cheers
Assuming that you are in the Root Folder (Folder with all the Other Folders),
Don't append #echo off to the batch file if you want to make sure that all is going well.
for /r %%F in (*.jpeg) do #for %%A in ("%%F\..") do ren "%%F" "%%~nxA.jpeg"
Detailed clarification on command coming soon.And as always with the Command Line, Bakup your files before doing anything :)
P.S. Tested, And it works. If using directly in CMD, change the double Percentages to Single Percentages (%%A > %A)

How to get a list of all subfolders sorted by date?

Is there any way to do that? Maybe some external program?
dir "d:\Folder" /ad /b /o:-d /s
Sorting is not working with "/s" and folders for me.
Compared to Unix-Shells the Windows Command Line Interface isn't very powerful. Windows PowerShell might be better for you, if Windows is mandatory for you. See this page for example.
OK I found an easy way to do this.
I just searched for "kind:folders" and sorted them by date.

How to compare two lists using CLI

I'm totally new to scripting, but would like to use Windows CLI compare two text files, list1.txt and list2.txt, each containing a list of values, and generate a new text file containing values that are found in one list but not in the other. I've been reading about Powershell, Shell, Batch files etc but cant seem to figure out the basics. Do I need to download anything to use these languages? Or how can I directly compare the files using the Windows CLI? Thanks.
This is very doable in PowerShell, which is preinstalled in windows 7+ and easily added in vista or less - look for some beginner powershell info on Google. You're going to want to use Get-Content and Compare-Object, then Where-Object to select which difference indicator you care about. Good luck!
To do this in the regular Windows shell, just do:
for /f "delims=" %A in (list1.txt) do #find "%A" "list2.txt" >nul2>nul || echo.%A>>list3.txt
or if you put it in a batch file, double the % signs.
for /f "delims=" %%A in (list1.txt) do #find "%%A" "list2.txt" >nul2>nul || echo.%%A>>list3.txt
This will give you all lines in list1.txt that do not exist in list2.txt, and save them into a file called list3.txt.

Dos command xcopy to have current date - 90 days variable

i need to a .bat file to copy with xcopy command the files from a specific directory that are 90 days new. that means to take the todays date and take out 90 days of it and do not perform the copy.
help is needed,
thx
Use ROBOCOPY not XCOPY. It will do what you want very easily. Robocopy is installed on Windows 7 and is a free download for other versions.
ROBOCOPY /S /MAXAGE:90 P:\path\to\source Q:\path\to\dest
There are many other options, for minimum age, min and max size, attrributes, filtering by file and directory names, and so forth.
Also you can use the /L option to just list what it would have done, to check you have the other options right.

Translate Windows NT "cmd /c dir /o:" To AIX

The title states my problem but I guess what I really need are some references. Help? Please?
dir /o means listing files in sorted order. Use the equivalent ls in AIX to achieve the same result. Experiment with option -t and -r as desired

Resources