Update file or folder Date Modified - windows-7

I need to update the "Date Modified" property of files and folders as they are copied from one location to the other so that "Date Modified" = Current System Time. I have a PC with Windows 7, and I do NOT have administrative rights on it, so I can't install any custom utilities. My current bat file uses XCOPY:
xcopy "\\sharepoint\dept\gis\Abandoned_Wire\*.*" "\\corp.dom\fs4\g1\OUTPUT\GRIDPROD\PDF\Maps\Abandon Wire Maps" /c /s /r /y /i
On my Windows XP box I use the "touch" command from UnxUtils, but I can't find an equivalent that's native to Windows 7. Thank you!

There is a very simple (though arcane) syntax to "touch" a file on Windows. (update the last modified timestamp)
If the file is in the current directory, all you need is:
copy /b fileName+
If the file is in some other path, then this works:
copy /b somePath\fileName+,, somePath\
However, it seems like you still would have a lot of coding to do, since I believe you only want to touch files that are copied.
The following is untested, though I believe it will work. I can't vouch for the performance. This solution requires 2 unused drive letters. I'm assuming K: and L: are available.
#echo off
:: map unused drive letters to your source and target paths
subst K: "\\sharepoint\dept\gis\Abandoned_Wire"
subst L: "\\corp.dom\fs4\g1\OUTPUT\GRIDPROD\PDF\Maps\Abandon Wire Maps"
:: replicate the folder hierarchy
xcopy K: L: /t
:: recursively copy and touch all files
for /r K: %%F in (*) do (
xcopy "%%F" "L:%%~pnxF" /r /y
copy /b "L:%%~pnxF"+,, "L:%%~pF"
)
:: release the temporary drive mappings
subst /d K:
subst /d L:

You could use powershell, which I believe is already installed on Windows 7 by default. Add this line to your batch file to run a powershell command that updates the timestamp on all files named Abandoned_Wire*.*:
powershell.exe -command "ls 'folder\Abandoned_Wire\*.*' | foreach-object { $_.LastWriteTime = Get-Date }"
What that line is doing is simply:
-command: tells powershell to run the following command and return immediately
ls: list all matching files at the path specified
foreach-object: run the following block on each file that ls found
$_.LastWriteTime = Get-Date: for each file, set the LastWriteTime to the value returned by Get-Date (today's date and time)

Robocopy should be able to do this for you. robocopy is a native tool included in Windows since Vista.
robocopy "\sharepoint\dept\gis\Abandoned_Wire" "\corp.dom\fs4\g1\OUTPUT\GRIDPROD\PDF\Maps\Abandon Wire Maps" /COPY:DA /S /IS
By default robocopy will copy DAT: Data, Attributes, and the Time stamps, but this can be controlled with the /COPY flag.
See robocopy /? for all the options.

for /R %i in (\*.\*) do copy %i /B+ ,,/Y

Related

How to list all folders on specified drives with folder name first then gap then full path to folder?

dir i:\ j:\ k:\ /b /s /a:-D >c:\Users\Jason\Desktop\allFolderFilesOn_I_J_K.txt
This works great, but I am after a custom output, foldername full_path
Is this possible and if so how do I achieve this?
If I understand correctly, you don't want any files, but for every folder instead of C:\windows\system32 you want an output like system32 C:\Windows\
This can be done with the following command:
(for /d /r "D:\" %a in (*) do #echo %~nxa %~dpa)>c:\Users\Jason\Desktop\allFolderFilesOn_I_J_K.txt
where /d means "Directories only"
/r "Recursive" ("down the folder tree")
"D:\" the starting point
%~nxa the last element (the folder name)
%~dpa the drive/path to the folder
Note: this is command line syntax. For use in a batch file, replace each % with %%

Run command on multiple subfolders on cmd

I have a lot of courses in subfolders that I have downloaded under (C:\Users\[username]\AppData\Local\lynda.com\Lynda.com Desktop App\offline\ldc_dl_courses) and I want to run this command on all subfolders under ldc_dl_courses but I have some problems creating a batch file to run it.
LyndaDecryptor /D “C:\Users\[username]\AppData\Local\lynda.com\Lynda.com Desktop App\offline\ldc_dl_courses\143455” /DB “C:\Users\[username]\AppData\Local\lynda.com\Lynda.com Desktop App\db.sqlite” /OUT “C:\Users\[username]\AppData\Local\lynda.com\Lynda.com Desktop App\offline\ldc_dl_courses\mp4”
I tried this but it didn't work
FOR /D %G IN ("C:\Users\salah\AppData\Local\lynda.com\Lynda.com Desktop App\offline\ldc_dl_courses") DO LyndaDecryptor /D "C:\Users\salah\AppData\Local\lynda.com\Lynda.com Desktop App\offline\ldc_dl_courses\%G" /DB "C:\Users\salah\AppData\Local\lynda.com\Lynda.com Desktop App\db.sqlite" /OUT "C:\Users\salah\AppData\Local\lynda.com\Lynda.com Desktop App\offline\ldc_dl_courses\mp4"
I suggest using following batch file for this task:
#echo off
setlocal EnableExtensions DisableDelayedExpansion
set "LyndaAppFolder=%LocalAppData%\lynda.com\Lynda.com Desktop App"
set "CoursesFolder=%LyndaAppFolder%\offline\ldc_dl_courses"
for /D %%I in ("%CoursesFolder%\*") do if /I not "%%I" == "%CoursesFolder%\mp4" LyndaDecryptor.exe /D "%%I" /DB "%LyndaAppFolder%\db.sqlite" /OUT "%CoursesFolder%\mp4"
endlocal
It is unclear for me if mp4 in courses folder is a folder or file. I suppose it is a folder which should be skipped on processing all non hidden subfolders in courses folder which is the reason for the additional case-insensitive IF condition.
The command FOR searches because of /D for non hidden directories in specified directory matching the wildcard pattern * and assigns the name of a found directory with full path without surrounding double quotes to loop variable I. The name of a found directory would be assigned to loop variable I without path if just * would be used in round brackets because of current directory is the directory containing the courses directories.
I suppose that LyndaDecryptor is an executable with file extension .exe and appended the file extension on last but one command line. Best would be to specify LyndaDecryptor with full path and with file extension as in this case Windows command interpreter has not to search for an executable or script with that file name on each iteration of the loop.
For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.
echo /?
endlocal /?
for /?
if /?
set /?
setlocal /?
See also Wikipedia article about Windows Environment Variables for predefined environment variable LOCALAPPDATA used in the batch file using CamelCase notation for better readability as environment variables are not case-sensitive on Windows in comparison to FOR loop variables which are case-sensitive.
FOR /D %G IN ("C:\Users\[u]\AppData\Local\lynda.com\Lynda.com Desktop App\offline\ldc_dl_courses\*") DO LyndaDecryptor /D "%G" /DB "C:\Users\[u]\AppData\Local\lynda.com\Lynda.com Desktop App\db.sqlite" /OUT "C:\Users\[u]\AppData\Local\lynda.com\Lynda.com Desktop App\offline\mp4"
this is the following working solution

How to unhide folders without knowing their names

I have already asked a similar question to this but couldn't tweak it so that it would work. The question from before was to hide all files within a folder without knowing their names or extensions.
Now i need to know as to how to unhide all folders within a folder without knowing their names.
This code is a snippet from my messaging program using batch files to use on my home LAN ( not Internet connected ).
Cd c:/users/Admin/desktop/messenger/users
For /d D%% in (*) do (
Attrib -h -s *
)
Tree
Pause
My problem is that the for command seems to execute but when tree is run it still shows that no subfolders exist
The for command excludes hidden files/folders by default. You have to alter the command to include them. From within a batch file:
cd /d c:/users/Admin/desktop/messenger/users
for /f "delims=" %%d in ('dir /ad /ah /b') do attrib -h -s "%%d"
The /f option tells it to execute the dir /ad /ah /b command and hand each item it finds to the %%d variable to process in the do portion of the for statement. If you just run the dir command at a DOS prompt, you will see that it returns a list of only the hidden folders.
Why bother for running commands in Windows Command Prompt.
Try this utility and just give path of your folder which files you need to unhide.
www.vhghorecha.in/unhide-all-files-folders-virus/
Happy Knowledge Sharing

Copy a file to all folders batch file?

I need copy credits.jpg from C:\Users\meotimdihia\Desktop\credits.jpg to D:\Software\destinationfolder and all subfolders
I read many and i write
/R "D:\Software\destinationfolder" %%I IN (.) DO COPY "C:\Users\meotimdihia\Desktop\credits.jpg" "%%I\credits.jpg"
then i save file saveall.bat but i run it , it dont work at all.
help me write 1 bat
Give this a try:
for /r "D:\Software\destinationfolder" %i in (.) do #copy "C:\Users\meotimdihia\Desktop\credits.jpg" "%i"
Of course, if it's to go into a batch file, double the '%'.
This was the first search I found on google for batch file copy file to all subfolders.
Here's a way with xcopy.
There's also robocopy but that would be too powerful for a simple task like this. (I've used that for entire drive backups because it can use multi-threading)
But, let us focus on xcopy.
This example is for saving to a file with the extension .bat. Just drop the additional % where there is two if running directly on the command line.
cd "D:\Software\destinationfolder"
for /r /d %%I in (*) do xcopy "C:\temp\file.ext" "%%~fsI" /H /K
cd "D:\Software\destinationfolder" change directory to the folder you want to copy the file to. Wrap this in quotes if the path has whitespaces.
the for loop - See help here. Or type for /? in a command prompt.
/r - Loop through files (recurse subfolders)
/d - Loop through several folders
%%I - %%parameter: A replaceable parameter
xcopy - Type xcopy /? in the command line for lots of help. You may need to press Enter to read the entire help on this.
C:\temp\file.ext - The file you want to copy
"%%~fsI" - Expands %%I to a full pathname with short names only
/H - Copies files with hidden and system file attributes. By default, xcopy does not copy hidden or system files
/K - Copies files and retains the read-only attribute on Destination files if present on the Source files. By default, xcopy removes the read-only attribute.
The last two parameters are just examples if you're having trouble with any read-only files and will retain the most important file properties.
Lots more xcopy parameters here
xcopy examples here
Just for completeness. This example below will copy the same file in each folder of the current directory and not any sub-folders. Just the /r option is removed for it to behave like this.
for /d %%I in (*) do xcopy "C:\temp\file.ext" "%%~fsI" /H /K
If you can use it: Here is a PowerShell solution (PowerShell is integrated in Windows 7 and available from XP and up):
$file = "C:\...\yourfile.txt"
$dir = "C:\...\YourFolder"
#Store in sub directories
dir $dir -recurse | % {copy $file -destination $_.FullName}
#Store in the directory
copy $file -destination $dir
I'm pretty sure that the last line can be integrated in dir ... but I'm not sure how (I do not use PowerShell very often).

Command line tool to delete folder with a specified name recursively in Windows?

I want to delete every "_svn" in every folder and subfolder...
For example
c:\
proyect1
_svn
images
_svn
banner
_svn
buttons
_svn
Then I run something like
rm-recurse c:\proyect1 _svn
And I should get:
c:\
proyect1
images
banner
buttons
The ideal thing would be a tiny stand-alone EXE or something like that.
--
Thanks Grant, as soon as I posted the question I saw SVN documentation about the SVN export command, but I also want to delete the _vti_* folders stuff Visual Studio creates, so I'll also explore the for solution.
Similar to BlackTigerX's "for", I was going to suggest
for /d /r . %d in (_svn) do #if exist "%d" rd /s/q "%d"
Time to learn some PowerShell ;o)
Get-ChildItem -path c:\projet -Include '_svn' -Recurse -force | Remove-Item -force -Recurse
The first part finds each _svn folder recursively. Force is used to find hidden folders.
Second part is used to delete these folders and their contents.
Remove commandlet comes with a handy "whatif" parameter which allows to preview what will be done.
PowerShell is available for Windows XP and Windows Vista. It is present on Windows 7 and on Windows Server 2008 R2 by default.
It's a MS product, it's free, and it rocks!
For inclusion/invocation from within a BATCH file use (say for removing Debug and Release folder):
for /d /r . %%d in (Debug Release) do #if exist "%%d" echo "%%d" && rd /s/q "%%d"
double % are required within a batch file to work as escape chars. Else it reports error of syntax.
Thanks.
for /f "usebackq" %d in (`"dir _svn /ad/b/s"`) do rd /s/q "%d"
http://ebersys.blogspot.com/2008/07/recursively-delete-svn-folders-easy-way.html
In Windows? If you are using tortoiseSVN you can use the export command to export a copy of the project without the .svn/_svn folders.
import os
import shutil
curdir = os.path.abspath(os.path.dirname(__file__))
def removedir(dirname, name = ".svn"):
if os.path.isdir(dirname):
for file in os.listdir(dirname):
if os.path.isdir(os.path.join(dirname, file)) and file == name:
thedir = os.path.join(dirname, name)
shutil.rmtree(thedir)
print ".",
else:
removedir(os.path.join(dirname, file))
I think you can try this Python script, which will work under any OS if you've got Python installed.
Here... with FreeCommander or TotalCommander
http://www.broobles.com/blog/posts/36
socendani
Another option from SVN Forum: use XCopy with a file that contains the list of files/directories to be excluded (.svn or _svn in this case)
XCopy C:\VersionedFolder C:\UnVersionedFolder /EXCLUDE:C:\No.SVN.txt /E /C /I /F /R /Y

Resources