I have a windows script here that takes all files in a source folder, whether they're nested or not, and moves them to one single destination folder.
However I have some duplicates within the source folders and every time it comes across one it prompts to copy or skip it. It is quite cumbersome as some of the source folders have a lot of duplicates.
Can someone advise on how to edit this script to make it auto skip any duplicates without prompting me every time or maybe even copy both and just append the name of the duplicate? Either one would work. I am still new to the whole batch script scene and it is driving me nuts.
The script I have is:
FOR /R "C:\source folder" %i IN (*) DO MOVE "%i" "C:\destination folder"
Thank you!
Related
So I am working on server files and have been successful in using Robocopy to make either copies of files or new ones in the designated directories.
robocopy "\\DIRECTORY\FOLDER\FOLDER1\FOLDER2" F:\DESTINATION\ /MIR /V /ETA /R:0 /W:0 /COPY:DATSO /LOG:"%logpath%%filename%" /NP
The thing I want to do now and what I am trying to focus on is being able to separate or at least group together all "NEW" files and all "SAME" files together because I get nearly 200k lines in the log and I don't want to be digging around when it can be just separated between the two categories and then grouped under which category the files fall under.
SAME
SAME
SAME
SAME
NEW
NEW
NEW
NEW
^That is the desired output but currently getting:
SAME
sAME
NEW
NEW
NEW
SAME
SAME
I am just reading through the manual as I am trying to make this so my explanation is hopefully clear. I am just focusing on getting the two separate after using Robocopy but the end goal is to pipeline all the new files somewhere else (that comes later though).
The scenario:
I have thousands of pictures (Both in .jpg and RAW), where each pair has the same name. I have looked through the JPGs and deleted hundreds of undesirable photos. Now I want the corresponding RAWs (The ones without "partner") deleted.
Everything is allowed: cmd, Windows Powershell, Scripts, hidden functions in Windows Explorer, ...
Speed is absolutely unimportant, you could have opened Windows Explorer, sorted by name highlighted all instances and deleted them in the time it took you to post this message and wait for an answer to your off-topic question.
Open a Command prompt window, (cmd.exe), CD to your directory holding these files; then enter this:
For %A In (*.RAW) Do #If Not Exist "%~nA.jpg" Del "%A"
So basically, I do a lot of mod work in my spare time. However, this can create an unnecessarily large amount of files that I want to delete.
So, I created a batch file that pretty much deletes every file (image files, model files, etc) but knowing myself, I have a gut feeling that I might one day accidentally open the batch file and screw myself over. What I'm wondering is, is it possible to create a "warning" in the batch file? Such as, "Warning! Proceeding will delete all files that haven't been backed up. Press any key to proceed." being an example? I haven't been able to find someone who has a similar request. Thanks for reading through this! I'd appreciate any help.
TL;DR: When a batch file is opened, is it possible to have a warning message that appears before any commands are run?
#echo off
set /p proceed=warning - enter x to proceed
if /i "%proceed%" neq "x" goto :eof
... now do your thing
You get prompted and must press x and enter to proceed.
A script shall process files in a folder on a Windows machine and mark it as done once it is finished in order to not pick it up in the next round of processing.
My tendency is to let the script rename the folder to a different name, like adding "_done".
But on Windows, renaming a folder is not possible if some process has the folder or a file within it open. In this setup, there is a minor chance that some user may have the folder open.
Alternatively I could just write a stamp-file into that folder.
Are there better alternatives?
Is there a way to force the renaming anyway, in particular when it is on a shared drive or some NAS drive?
You have several options:
Put a token file of some sort in each processed folder and skip the folders that contain said file
Keep track of the last folder processed and only process ones newer (Either by time stamp or (since they're numbered sequentially), by sequence number)
Rename the folder
Since you've already stated that other users may already have the folder/files open, we can rule out #3.
In this situation, I'm in favor of option #1 even though you'll end up with extra files, if someone needs to try and figure out which folders have already been processed, they have a quick, easy method of discerning that with the naked eye, rather than trying to find a counter somewhere in a different file. It's also a bit less code to write, so less pieces to break.
Option #2 is good in this situation as well (I've used both depending on the circumstances), but I tend to favor it for things that a human wouldn't really need to care about or need to look for very often.
I'd like to change folder contents without having Date modified change.
I sometimes do cleanup runs on old folders, trying to make space or clean up temp files and dead-ends, or adding relevant links or tags for findability. When I do this, I don't want to change the folder to Date modified: today 2015, because my folders are sorted by Date modified. A project from 2010 should remain timestamped with its last modified date from 2010, because I've only made meta-changes, not actual changes.
Currently I use SK Timestamp or Attribute Changer. I right click each folder before I want to make changes to it, I keep the Properties window open, make my modifications, then hit Apply to overwrite the original timestamps.
I'd like to do it more automated, like set a Cleanup Mode on the root folder D:\Workspace and until I pop that state no timestamps ever get changed in the subdirectories Project2010, Project2013..., Project2015
Either that or at least be able to copy the timestamp between 2 files. Like in this answer that mentions #COPY /B %1+,, %1, but not with current date.
Usage like: touch D:\Temp\Project2010\Source.txt Destination.ext
I had commented above with a couple of suggestions -- one involving modifying the system's date / time, and another involving robocopy. The system date / time one is a bit of trouble and requires Internet access, and the robocopy /dcopy:t switch didn't work at all in my tests.
But I found a better solution anyway. Use a for loop to capture the folder's date time to a variable. Then after you've made whatever changes you wish, use powershell to put the folder's date / time back the way it was.
#echo off
setlocal
set "dir=path\to\directory"
for %%I in (%dir%) do set "datetime=%%~tI"
:: Do whatever deletions and other maintenance you want here.
:: Then after all changes have completed, reset the dir timestamp.
powershell -command "(Get-Item '%dir%').LastWriteTime=(Get-Date '%datetime%')"