Update timestamp of a directory on Windows - windows

There is more or less well-known command line way to update the modification time of a file on Windows (described at Update file or folder Date Modified, for example):
copy /b somePath\fileName+,, somePath\
According to my experience it does for a file, but does not for a directory (tested on WinXP - the command did not fail, but the directory modification time was not updated).
I tried to adjust it for a directory using such a trick that we can "point" to the directory using a special "NUL" filename on Windows. I tried two ways to do that, but they don't work as well:
copy /b somePath\fileName\NUL+,, somePath\filename\
copy /b somePath\fileName\NUL+,, somePath\
Could anyone explain me why it does not work or what I am doing wrong?

It doesn't make any changes to the directory because the filename nul is not stored in the directory. Since the directory is not changed, its modification time doesn't change. You can do this instead:
type nul > somePath\fileName\SomeFileThatDoesNotExist.tmp && del somePath\fileName\SomeFileThatDoesNotExist.tmp

Related

Creating metadata with CMD?

In a security+ class we were shown how to inject exes and etc into a file using CMD line. The command was along the lines of:
CMD > Notepad.exe "file.exe:otherfile.exe"
In his explanation it added Notepad to file.exe by the name of otherfile.exe.
The problem with this is that he claims it is injecting a file directly into that file, but he showed us how the file size doesn't change but total NTFS file system size changes.
I believe he is talking about generic metadata and not changing the file in any way. Can someone please clarify or give me a reference to the command he is talking about or a good explanation?
Try this, it may answer a few of your questions:
md test
cd test
dir
echo this is my file>file.txt
dir
echo alternative data stream>file.txt:hidden
dir
dir /r
del file.txt
dir /r

How to use the list files in a given directory via batch file without showing the full path?

I have searched for this everywhere so I hope it has not already been asked, but I have a batch file where the user can write his / her own 'scripts' if you will. When the batch file is ran for the first time it will make a directory under %appdata%\Mellow\Mango\scripts and these scripts will simply be .txt files. Anyway...
I am trying to list the 'scripts' to the user by using dir /b /s *.txt and the output is C:\Users\Tate\AppData\Roaming\Mellow\Mango\scripts\template.txt
My question is, sorry if I got off-topic before, how to display only template.txt and not the full file path. I simply would like to list all .txt files contained in the scripts folder. Thanks in advanced!
Current Output:
C:\Users\Tate\AppData\Roaming\Mellow\Mango\scripts\template.txt
C:\Users\Tate\AppData\Roaming\Mellow\Mango\scripts\another_script.txt
Desired Output:
template.txt
another_script.txt
Simply remove the /s
dir /b *.txt
That should do it :)

Populating empty folders recursively with Windows

I have a huge series of folders, named 'A' through 'Z' such that each folder has subfolders in the same form.
For example, I could have a directory at this path: .\A\D\E
I want to populate each of these folders with an empty file (so I can commit it to a git repository if anyone's curious).
Windows doesn't have an equivalent of Linux's touch, but I have the GnuWin32 toolset installed so I can, in fact, use touch in my Windows environment.
I've started by creating a batch file with the following:
FOR /D /r do touch empty
But when I run it, the folders aren't populated. I don't get any errors either:
C:\sandbox>FOR /D /r do touch empty
C:\sandbox>
Does anybody see anything glaringly wrong about the line of batch script above? Is there anything else I can try short of using additional non-Windows commands?
You just need to get the syntax of the FOR command right:
for /r %f in (.) do touch %f\empty

how to batch replace the files in a directory windows vista(from .txt.txt to .txt)

I have a couple of flat files(.txt) in a directory.all those files are in the format *.txt.txt so i want to rename it to *.txt ?Is there any simple way to rename all together?
when I tried ren *.txt.txt *.txt is is not working
Any experts please suggest?It is amazing I have not got any answer yet
Please be noted that I need an out of the format filename.txt.
This should work
ren *.txt.txt *.
The reason your command didn't work is because, to windows, the file file.txt.txt is called file.txt with a .txt extension.
Only the last extension is the real extension, the first then becomes part of the filename, hence why your command changes it to what it already is.
If you did ren *.txt.txt *.pdf you would get file.txt.pdf.
My command will just remove the last one, thereby leaving the first, which then becomes the only and real extension.

Mercurial/extdiff not changing to temp dir (as I THINK it's supposed to)

Using Windows, Mercurial, and the extdiff extension (for Mercurial). I was trying to set up extdiff to use WinDiff as an external diff tool, but I think I've narrowed the problem down enough to say that the trouble is before I'm even getting that far.
From what I understand of extdiff, it merely calls your cmd.winmerge program, and passes the necessary directories to it. I'm also working off of some assumptions outlined here (which may or may not be accurate; I'm just learning Mercurial):
http://bitbucket.org/tortoisehg/stable/issue/457/multiple-extdiff-threads-in-one-process-causes-side#comment-36216
which says:
The extdiff (visual diff) extension works like this:
1-Generate temporary directory(ies) for older changesets
2-run util.system( cwd=tempdir, "yourdiff tool dir1 dir2" )
util.system does:
2.1 store cwd;
2.2 cd tempdir
3-run your diff tool, wait for it to exit
4-cd oldcwd
5-Then finally extdiff deletes the temp directories.
The trouble that I'm having is that extdiff doesn't seem to be changing into the temp directory before proceeding, as it appears it is supposed to do in step 2.1 above.
In trying to isolate the problem, I wrote a batch file just to see what the cd was, what was being passed, and how exactly it was being passed. The batch file is as follows:
#echo off
echo %cd%
echo %1
echo %2
D:\Documents\apps\WinMergePortable\App\WinMerge\WinMergeU.exe %1 %2
I then set up extdiff to use this batch file as my extdiff program. This works, but I see that when it echoes %cd%, it's just c:\ , not c:\temp as expected. I've verified that extdiff is creating the temporary files in the proper temporary directories (as it's supposed to per step 1 above; something like c:\temp\extdiff.xxxxxx\someFolder.someChangesetID\file.ext), so I know it's SEEING those directories. It's just not properly changing into them before it's calling WinMerge, so when WinMerge is opened, it doesn't see the temp files (since it's not in the proper working directory).
That's basically where I'm stuck. I don't know where else to go from here. I thought of just putting
cd %tmp%
in my batch file, but that still doesn't grab the extdiff.xxxxx\ subdirectory which extdiff is creating the temp files in.
In summary: :-(
EDIT: Changing the batch file to
#echo off
echo %cd%\extdiff*
echo %1
echo %2
D:\Documents\apps\WinMergePortable\App\WinMerge\WinMergeU.exe %1 %2
seems to make it work (note changed second line), but it still seems a nasty hack to instead of how it's supposed to work. :-\
EDIT: Here is my Mercurial.ini file:
[ui]
username = Tim Skoch <my_real#email.address>
editor = D:\Documents\apps\Notepad++\notepad++.exe -multiInst
[extensions]
hgext.graphlog =
hgext.extdiff =
[extdiff]
cmd.winmerge = d:\Documents\apps\mercurial\diff_winmerge.bat
I can confirm that extdiff will change to a temporary directory before starting your diff program. You can use --debug to see this. Here I'm using true as the diff program (it just exist immediately):
$ hg extdiff -p true --debug
making snapshot of 2 files from rev 18480437f81b
a
b
making snapshot of 2 files from working directory
a
b
running "'true' 'foo.18480437f81b' 'foo'" in /tmp/extdiff.IJ9clg
cleaning up temp directory
The two arguments for the diff program are directories: a snapshot directory for the old versions and one for the new versions. They are inside the /tmp/extdiff.IJ9clg temporary directory.
One confusing point is that the arguments for the diff program are different depending on the number of modified files. With just one modified file, there is no need to create a
snapshot of the working copy. So if a is the only modified file, you'll see
$ hg extdiff -p true --debug
making snapshot of 1 files from rev 18480437f81b
a
running "'true' '/tmp/extdiff.mUlnP_/foo.18480437f81b/a' '/home/mg/tmp/foo/a'"
in /tmp/extdiff.mUlnP_
cleaning up temp directory
Here the diff program was started with two files as arguments. As described in hg help -e extdiff, you can use some variables to build the command line. The default corresponds to $parent $child.
You say that WinMerge "cannot find the files correctly". There are other questions and answers on SO about WinMerge and they seem to have it working just fine. Maybe you can try their command line options.

Resources