Windows Batch File that Copy Rated Files - windows

Hi StackOverflow Community,
I would like to ask if there's a way to copy the files which are rated using a Windows Batch Job (.bat).
The files are photos, and some were rated in-camera. When all of these files (rated and unrated) are copied to my hard drive, I would like to let the batch job automatically copy out the files that are rated into another folder.
I know that my computer has no problem viewing the ratings as when I view the Properties of the rated files, a number of stars are displayed in it.
Any help is much appreciated, and thank you in advanced =)

Check tooltipinfo.bat.If the passed item is rated it will have in the output something like :
Rating: 5 Stars
so you need the tooltipinfo.bat in your directory.Then create batch file like :
(not tested)
#echo off
set folder_with_the_items=C:\photos_and_videos
set destination_folder=C:\somewhere_else
for /f "tokens=* delims=" %%a in ('dir /a:-d /b /s "%folder_with_the_items%\*"') do (
call tooltipinfo.bat "%%~fa" | find /i "Rating:" >nul 2>nul && (
copy "%%~fa" "%destination_folder%"
)
)
As you'll need to change the folder locations at the beginning of the script.

Related

How to write a batch file to delete multiple specific files from different paths?

Each time before I start debugging, I need to delete some specific files from different paths. It's a tiresome process as I do it like a million times in a day. So I want to write a batch file that deletes all those at once without prompting.
The first path is
C:\Users\irem\AppData\Roaming\JDeveloper\systemx\DD\servers\DefaultServer\tmp\
I want everything under this temp folder gone. Without the temp folder itself, of course.
The second path is
C:\Users\irem\AppData\Roaming\JDeveloper\systemx\o.j2ee\drs\
I again want everything under this drs folder gone. Again without the drs folder itself, of course.
The third path is
C:\Users\irem\AppData\Roaming\JDeveloper\systemx\
This time I want to delete only the files with .lok extension under the systemx folder.
I tried to write something like this:
del "C:\Users\irem\AppData\Roaming\JDeveloper\systemx\DD\servers\DefaultServer\tmp\*.*?" /s
& del "C:\Users\irem\AppData\Roaming\JDeveloper\systemx\o.j2ee\drs\*.*?" /s
& del "C:\Users\irem\AppData\Roaming\JDeveloper\systemx\*.lok"
However it doesn't meet my expectations, it doesn't work.
I appreciate all the help. Thank you very much.
Perhaps something like this would do what you want:
#Echo Off
Set "srcPath=%AppData%\JDeveloper\systemx"
Set "tmpPath=DD\servers\DefaultServer\tmp"
Set "drsPath=o.j2ee\drs"
CD /D "%srcPath%" 2>Nul || Exit /B
Del /F /Q /A *.lok
For /D %%A In ("%tmpPath%\*" "%drsPath%\*") Do (RD /S /Q "%%A"
Del /F /Q /A "%%A\*.*")
I have used the paths you provided in your question, if those have changed, you can alter them by editing lines 2, 3 and 4 as necessary.

batch delete with directory variable - windows 7

I use the following batch file to delete unwanted files on several drives.
set /p DELPATH=<"C:\DELETE-ALL.txt"
for /f "usebackq delims=;" %%i in ("C:\DELETE-ALL.txt") do #del /q "D:\HFI\%DELPATH%\%%i" > C:\DELETE-ALL-4.txt 2>&1
... same command for other local and network drives.
The DELETE-ALL.txt looks like this:
mydirectory
TEST.xlsx
TEST2.xlsx
This works great. It deletes files in single directory. But now I need it to do more. I need the batch file to delete files in different directories. So, it boils down to how to change directory on the fly.
Any help will be greatly appreciated.
I answer you here because i can't comment now with my lower reputation.
I strongely recommend to use PowerShell or python or others program scripts to do this. Using windows batch, it will take you more time to find a good way and there may be no way to do such a little complex misson.
The answer turns out to be easier than I thought. Although my original question was for deleting files, I got it to work for rename. It should work for delete with little modification.
#(for /f "tokens=1,2 delims=;" %%A in ('"TYPE C:\RENAME-ALL.txt"') do (
#echo "%%A" | find /i "\"
#if errorlevel 1 (
RENAME "%%A" "%%B" >> C:\RENAME-ALL-4.txt 2>&1
) ELSE (
CD /D D:\mydirectory\%%A
)
)
)
The script looks for "\". If found, it assumes that line is a directory and change to the corresponding directory with "D:\mydirectory\" as a path prefix. Otherwise, it assumes the line contains file name. Since back slash is not allowed in filename, the assumption is safe.
Hope this will help other people.

Windows batch file to find duplicates size files in harddisk (no matter the name and the extension)

I'd like a batch file ( Windows CMD is the interpreter, a .bat ) to do this type of task:
1) Search through a folder and its subfolders (entire harddisk)
2) Find files with the same size (no matter filename and extension)
3) Display these files (or not)
Thank you for any kind of help! :)
EDIT:
With the following commands, I can know all sizes that the files have...
#echo off
set "filename=*.*"
for %%A in (%filename%) do echo.Size of "%%A" is %%~zA bytes
but now the big problem is that you need to compare the first, with the remainder and so on!
The Batch file below should solve your problem; however, be aware that in despite of its apparent simplicity, it is based on advanced concepts, like array management in Batch files.
#echo off
setlocal EnableDelayedExpansion
rem Group all file names by size
for /R %%a in (*.*) do (
set "size[%%~Za]=!size[%%~Za]!,%%~Fa"
)
rem Show groups that have more than one element
for /F "tokens=2,3* delims=[]=," %%a in ('set size[') do (
if "%%c" neq "" echo [%%a]: %%b,%%c
)
This program may take too much time if the number of files is large or if the starting folder have a long path.

Batch file to move many listed files to one specific folder

I have a Master folder which have multiple sub folders. All the subfolders have lot images with different extensions (jpg,tif and png). The total number of images in all the subfolder are around 90000 images.
The thing is, I need to search some 500 images in Master folder and its subfolders and move the images to specified folder.
I tried a below batch script to use the text file to search through a Master folder and all subfolders and move all the files from the list and paste them into a Specified single folder.
The text file which contains file names without extension.
But my batch script is not working. It didnt throw me any error.. but nothing happens when I run it.
set FIILELIST=C:\padhu\files.txt
set FILESPATH=C:\Padhu\MasterFolder
set DESTPATH=C:\DestinationFolder
for /f %%X in (%FIILELIST%) do call :MOVE_FILES "%%X"
goto :eof
:MOVE_FILES
for /r %FILESPATH% %%I in (%~1) do echo move /qvs "%%I" "%DESTPATH%%%~pnxI"
I am very new to batch script and in learning stage. Kindly help me in this. Im very much thankful if anyone provide the correct batch script to do this.
Can you try this?
set FIILELIST=C:\padhu\files.txt
set FILESPATH=C:\Padhu\MasterFolder
set DESTPATH=C:\DestinationFolder
for /f "delims=" %%x in (%FIILELIST%) do (forfiles /p %FILESPATH% /s /m %%x.* /c "cmd /c move /y #path %DESTPATH%\#file" 2>>failed_temp.txt)
for /f "tokens=5 " %i in (failed_temp.txt) do (echo.%~i)>>failed_list.txt
del failed_temp.txt
Cheers, G
#gbabu's answer was super helpful for me.
I needed to edit it to handle file names that were absolute (full) instead of relative. And I needed to handle that they contained spaces.
Unfortunately I couldn't figure out how to log the errors like #gbabu did.
#echo off
REM See https://stackoverflow.com/a/25325529/470749
REM See https://stackoverflow.com/a/163873/470749
REM See https://stackoverflow.com/a/155950/470749
set FILELIST="K:\F\Users\my_user\Documents\My Music\JUKEBOX\5.m3u_list.txt"
set DESTPATH=C:\temp\cdrw
for /f "usebackq tokens=*" %%x in (%FILELIST%) do (copy "%%x" %DESTPATH%)
pause
These articles helped me:
https://stackoverflow.com/a/25325529/470749
https://stackoverflow.com/a/163873/470749
https://stackoverflow.com/a/155950/470749

Windows 7 desktop.ini shared folder removal script bug

Bit of a batch file question. I imagine lots of people are having fun with shared folders appearing as "My Documents" in windows explorer.
I look after several schools, where we have the pupil home folders set in a folder called say C:\data\pupils\yeargroup...
The teachers then have access to the pupils folder on a share & can review the pupils work. With the onset of Windows 7, whereas before Yeargroup folders have had a list of the pupils names with their mydocs inside, you now see a whole load of folders reporting to be "My Documents" due to the desktop.ini located inside of them.
So, I wrote this little batch file & have been running it in c:\data on a 15 minute automated task which has done a nice job or restoring law & order:
FOR /f "delims=" %%i IN ('dir /s /b /a-d "desktop.ini"') DO attrib -s -h %%i >nul 2>nul
FOR /f "delims=" %%i IN ('dir /s /b /a-d "desktop.ini"') DO del %%i >nul 2>nul
The has worked fine up until deployment at a new site that I've just got involved with. Whereas I set up all folders without spaces:
C:\data\pupils\yeargroupx\joebloggs
the folder names at this site are something like this:
C:\data\pupils\yeargroup x\joe bloggs
I have tested running the commands manually & seem to have to run the following (from within the folder location):
dir /ash
attrib -s -h
del desktop.ini
As there are 100s of users, I obviously want to automate this. Any ideas as to how I would tweak my script? I want to do dir /ash for every folder before I change the attribute of the ini file, otherwise cmd cannot see it.
I got that script running through fudging about rather than any in depth knowledge, so some assistance would be greatly appreciated?
Use "%%i" in the command tails and then spaces and & will not be a problem.

Resources