jaclaz Posted May 31, 2012 Share Posted May 31, 2012 Of course I could,...You see , no need to make Coffefiend UNemployed And now, for NO apparent reason, an unneededly complex script using WMIC! @ECHO OFFSETLOCAL ENABLEEXTENSIONSPUSHDCD /D %1set "thisfolder=%CD:~2%"for /F "skip=1 tokens=*" %%A in ('"wmic datafile where (path='%thisfolder:\=\\%\\') get InstallDate, Name"') do (SET Line=%%ACALL :parse_date)POPD:parse_dateSET Y=%Line:~0,4%SET M=%Line:~4,2%SET D=%Line:~6,2%SET Name=%Line:~27%ECHO %D%/%M%/%Y% - %Name%GOTO :EOFjaclaz Link to comment Share on other sites More sharing options...
gunsmokingman Posted May 31, 2012 Share Posted May 31, 2012 Here is a VBS Script that, you Drag & Drop the folder that you want to list in below format. This willgo threw all Folders And Sub Folders, and list all contents.Source Folder Path1\ Name2:\ Created3\ Accessed4\ ModifiedSave As List_File_Directory.vbs'-> This code is property of Gunsmokingman and Or Jake1Eye and you must have his permission to use.'-> This is only posted as example code and meant only to used as such.'-> Object For Run TimeDim Act :Set Act = CreateObject("Wscript.Shell")Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")'-> Varibles For Script Run TimeDim Ar, Dr, Ln, Ts, TxtAr = Chr(160) & Chr(187) & Chr(160)Ln = "--------------------------------------------------------"'-> Makes Sure Only One Object Drag And DropSelect Case WScript.Arguments.CountCase 0call Msg(vbTab & "Error No Folder" & vbCrLf & _"To Use This Script Drag And Drop An" & vbCrLf & _"Single Folder Onto This Script.","Error 1")Case 1'-> Filter Out File From FolderIf Right(InStr(WScript.Arguments.Item(0),"."),6) Thencall Msg(Space(26) & "File Drag Drop" & vbCrLf & _" You Have Drag & Drop A File Onto This Script." & vbCrLf & _"Script Requires Only One Folder To Be, Drag &" & vbCrLf & _"Drop To Make Active","Error 3")ElseDr = WScript.Arguments.Item(0)call Msg("Preparing To List This Folder : " & Dr, "List Contents", 4128)Txt = Act.SpecialFolders("DeskTop") & "\List_Item.txt"Set Ts = Fso.CreateTextFile(Txt)Ts.writeline vbTab & "Scan Time" & Ar & Time()Ts.writeline vbTab & "Scan Date" & Ar & Date()Ts.writeline vbTab & "Scan Path" & Ar & DrRecursive(Fso.GetFolder(Dr))Ts.WriteLine LnTs.CloseAct.Run(Txt),1,Truecall Msg("Did You Want To Keep This File : " & Fso.GetFile(Txt).Name & vbCrLf & _"No To Delete This File, Yes To Keep File If Nothing Is Select" & vbCrLf & _"In 5 Seconds, This Script Will Close And Save The File","Yes To Keep - No To Delete",4132)End IfCase Elsecall Msg(Space(25) & "Error Exceeds Limit" & vbCrLf & _" User Has Drag And Drop " & WScript.Arguments.Count & _" Objects On To This Script." & vbCrLf & "This Script Was Meny To" & _" Process Only One Folder, At" & vbCrLf & " Script Run Time", _"Error 2", 4128)End Select'-> Msgbox Function With 5 Second TimeOutFunction Msg(Tx, Tn, Btn)Select Case BtnCase 4128Act.Popup Tx, 5, Tn, 4128Case 4132If Act.Popup(Tx, 5, Tn, 4132) = 7 Then Fso.DeleteFile(Txt), TrueEnd selectEnd Function'-> Recusive Threw Folder And All Sub FoldersFunction Recursive(Folder)Ts.WriteLine LnTs.WriteLine " Folder Path " & Ar & FolderFor Each Obj In Folder.FilesTs.WriteLine LnTs.WriteLine " File Name " & Ar & Obj.NameTs.WriteLine " Date Created " & Ar & Obj.DateCreatedTs.WriteLine " Last Accessed" & Ar & Obj.DateCreatedTs.WriteLine " Last Modified" & Ar & Obj.DateCreatedNextFor Each Dir In Folder.subFoldersRecursive(Dir)NextEnd Function Link to comment Share on other sites More sharing options...
jaclaz Posted June 1, 2012 Share Posted June 1, 2012 Here is a VBS Script that, you Drag & Drop the folder that you want to list in below format. This will ....Very good , everything is back to normality :Now that the OP issue is solved, can we go a step ahead (or aside )?The WMIC thingie I posted is seemingly "absurd" (using the "containing folder and "Installdate" ), but I got to it because I had issues with:@ECHO OFFSETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSIONSET TargetDir="%*"SET TargetdirPUSHDCD /D %TargetDir%REM DIRPauseFOR /F "tokens=*" %%A IN ('DIR /A:-D /B %TargetDir%') DO CALL :getCreationDate "%%A"POPDgoto :eof:getCreationDateset FILE=%~f1set FILE="%FILE:\=\\%"FOR /F "skip=1 tokens=*" %%B IN ('"wmic datafile where (name=%FILE%) get creationdate, name"') DO (SET Line=%%BSET Line=!Line:~6,2!/!Line:~4,2!/!Line:~0,4! !Line:~26!ECHO !LINE! )goto :eofNamely the batch is "borked" if a name conataining brackets is found.I tried a few alternative things in the FOR loop, including attempting using the usebackq parameter, but could not find any solution. jaclaz Link to comment Share on other sites More sharing options...
Yzöwl Posted June 1, 2012 Share Posted June 1, 2012 but I got to it because I had issues with:@ECHO OFFSETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSIONSET TargetDir="%*"SET TargetdirPUSHDCD /D %TargetDir%REM DIRPauseFOR /F "tokens=*" %%A IN ('DIR /A:-D /B %TargetDir%') DO CALL :getCreationDate "%%A"POPDgoto :eof:getCreationDateset FILE=%~f1set FILE="%FILE:\=\\%"FOR /F "skip=1 tokens=*" %%B IN ('"wmic datafile where (name=%FILE%) get creationdate, name"') DO (SET Line=%%BSET Line=!Line:~6,2!/!Line:~4,2!/!Line:~0,4! !Line:~26!ECHO !LINE! )goto :eofNamely the batch is "borked" if a name conataining brackets is found.I tried a few alternative things in the FOR loop, including attempting using the usebackq parameter, but could not find any solution. jaclazFirst of all you are asking your script to do too much work!Instead of creating a command to list each file and performing another command on each file, you can work directly on the input directory.Once you've reduced the work you simply need to change the way you format your WMIC syntax, (remember too that the comma needs escaping)Try this:@ECHO OFF & SETLOCAL ENABLEEXTENSIONS DISABLEDELAYEDEXPANSIONIF %1' EQU ' GOTO :EOFSET "P_=%~1"SET "P_=\%P_:*\=%\"FOR /F "USEBACKQ TOKENS=1*" %%# IN (`WMIC DATAFILE WHERE^ "DRIVE='%~d1' AND PATH='%P_:\=\\%'" GET CREATIONDATE^, NAME^|FIND /I "%~d1"` ) DO CALL :_O "%%#" "%%$"PAUSE & GOTO :EOF:_OSET "D_=%~1"ECHO=%D_:~6,2%/%D_:~4,2%/%D_:~,4% %~2 Link to comment Share on other sites More sharing options...
jaclaz Posted June 1, 2012 Share Posted June 1, 2012 Try this:I'll do and report, as soon as I am back to the machine I normally work with, thanks .But though - as always - very nice , it is a (much better) workaround.I mean your script still uses "directory" info and not "filename", set aside the OP request, if instead of looking for the created date of the contents of a directory I want to look for the created date of a single file, I need to use the "WHERE Name=" approach.What I am missing (and I want to understand fully) is the right way to escape/quoting everything in the FOR loop.I'll study your approach, if I get it right is:use USEBACKQenclose the whole set of arguments of WHERE in double quotesenclose the values of each single comparison inside the WHERE in in single quotesescape the commas (besides - as always - the pipe symbol) and see if it works with the filename containing bracketsjaclaz Link to comment Share on other sites More sharing options...
Yzöwl Posted June 1, 2012 Share Posted June 1, 2012 I mean your script still uses "directory" info and not "filename", set aside the OP request, if instead of looking for the created date of the contents of a directory I want to look for the created date of a single file, I need to use the "WHERE Name=" approach.My reading of your intention was to provide the date created for each file within a 'input' directory. Just drag and drop a directory onto the script, it should do just that. Link to comment Share on other sites More sharing options...
jaclaz Posted June 2, 2012 Share Posted June 2, 2012 Working perfectly Here is the very slighlty modified version that deals with single file:@ECHO OFFSETLOCAL ENABLEEXTENSIONS DISABLEDELAYEDEXPANSION IF %1' EQU ' GOTO :EOFIF NOT EXIST %1 GOTO :EOFSET "P_=%~1" FOR /F "SKIP=1 USEBACKQ TOKENS=1*" %%# IN (`WMIC DATAFILE WHERE "NAME='%P_:\=\\%'" GET CREATIONDATE^, NAME` ) DO CALL :_O "%%#" "%%$" PAUSE & GOTO :EOF :_O SET "D_=%~1" ECHO=%D_:~6,2%/%D_:~4,2%/%D_:~,4% %~2jaclaz Link to comment Share on other sites More sharing options...
Yzöwl Posted June 4, 2012 Share Posted June 4, 2012 Here is the very slighlty modified version that deals with single file:@ECHO OFFSETLOCAL ENABLEEXTENSIONS DISABLEDELAYEDEXPANSION IF %1' EQU ' GOTO :EOFIF NOT EXIST %1 GOTO :EOFSET "P_=%~1" FOR /F "SKIP=1 USEBACKQ TOKENS=1*" %%# IN (`WMIC DATAFILE WHERE "NAME='%P_:\=\\%'" GET CREATIONDATE^, NAME` ) DO CALL :_O "%%#" "%%$" PAUSE & GOTO :EOF :_O SET "D_=%~1" ECHO=%D_:~6,2%/%D_:~4,2%/%D_:~,4% %~2You could improve on that too because there's no need to create a command which gives you something you already know, i.e. the files name.@ECHO OFF & SETLOCAL ENABLEEXTENSIONS DISABLEDELAYEDEXPANSIONIF %1' EQU ' GOTO :EOFSET "P_=%~1" & SET "D_="FOR /F "USEBACKQ" %%# IN (`WMIC DATAFILE WHERE "NAME='%P_:\=\\%'" GET^ CREATIONDATE^|FIND "+"`) DO SET D_=%%~#ECHO=%D_:~6,2%/%D_:~4,2%/%D_:~,4% %~nx1PAUSEYou could obviously replace %~nx1 with %~f1 or %P_% if you prefer Link to comment Share on other sites More sharing options...
jaclaz Posted June 4, 2012 Share Posted June 4, 2012 You could improve on that too because there's no need to create a command which gives you something you already know, i.e. the files name.Yep, of course .I am a bit perplexed by the FIND "+"I had gathered that the offset could be both + and - (plus and minus) http://technet.microsoft.com/library/ee198928.aspxjaclaz Link to comment Share on other sites More sharing options...
Yzöwl Posted June 4, 2012 Share Posted June 4, 2012 I thought you were in Italy, which is a plus offset Link to comment Share on other sites More sharing options...
bphlpt Posted June 5, 2012 Share Posted June 5, 2012 So to adjust the code to work in the US you change the "+" to "-"? And if you wanted to make the code general purpose that would work everywhere?Cheers and Regards Link to comment Share on other sites More sharing options...
CoffeeFiend Posted June 5, 2012 Share Posted June 5, 2012 if you wanted to make the code general purpose that would work everywhere?Then you also have to worry about difference in the date/time formats as well when you parse that text (it changes with different cultures/locales). There's so many ways to accomplish that stuff in most languages. A couple quick PowerShell examples:For output with a standard ISO time format:ls C:\path\here\|sort CreationTime|%{$_.CreationTime.ToString("s")+" "+$_.Name}For output with a custom YYYY-MM-DD format (good for sorting):ls C:\path\here|sort CreationTime|%{$_.CreationTime.ToString("yyyy-MM-dd")+" "+$_.Name}Same ISO format output, but with code written in a different way:ls C:\path\here|sort CreationTime|%{[string]::Format("{0:s} {1}",$_.CreationTime,$_.Name)}There's *so* many other ways to do it, using so many languages. It's very simple in in VBScript as well, except for the sorting part where you have to write your own sort function... Link to comment Share on other sites More sharing options...
Yzöwl Posted June 5, 2012 Share Posted June 5, 2012 So to adjust the code to work in the US you change the "+" to "-"? And if you wanted to make the code general purpose that would work everywhere?Well you could go for a findstr covering both options:@ECHO OFF & SETLOCAL ENABLEEXTENSIONS DISABLEDELAYEDEXPANSIONIF %1' EQU ' GOTO :EOFSET "P_=%~1" & SET "D_="FOR /F "USEBACKQ" %%# IN (`WMIC DATAFILE WHERE "NAME='%P_:\=\\%'" GET^ CREATIONDATE^|FINDSTR [+-]`) DO SET D_=%%~#ECHO=%D_:~6,2%/%D_:~4,2%/%D_:~,4% %~nx1PAUSEOr find something unique to the output line only, I'd be inclined to think that a 0 will always be there:@ECHO OFF & SETLOCAL ENABLEEXTENSIONS DISABLEDELAYEDEXPANSIONIF %1' EQU ' GOTO :EOFSET "P_=%~1" & SET "D_="FOR /F "USEBACKQ" %%# IN (`WMIC DATAFILE WHERE "NAME='%P_:\=\\%'" GET^ CREATIONDATE^|FIND "0"`) DO SET D_=%%~#ECHO=%D_:~6,2%/%D_:~4,2%/%D_:~,4% %~nx1PAUSE Link to comment Share on other sites More sharing options...
jaclaz Posted June 5, 2012 Share Posted June 5, 2012 I thought you were in Italy, which is a plus offsetAs a very respectable member said not so long ago : Your second attempt made assumptions and is therefore discounted as a proper solution. Seriously:What is the issue with "SKIP=1"?What if the "^,Name" is kept (though redundant) and one uses "FIND "\"?jaclaz Link to comment Share on other sites More sharing options...
Yzöwl Posted June 5, 2012 Share Posted June 5, 2012 I'm not assuming that you're in Italy, your flag is Italian and IP address is Italian, (telecomitalia.it). Since I was replying directly to you, there was no reason not to structure my response directly to you.The output of WMIC cannot be guaranteed to produce a specific number of lines, therefore the prudent thing to do is to skip all but your intended line, not skip the first line and keep all others. You can output information you don't need in order to have something definite to FIND if you wish, it's your script, but since you know when you formulate your GET's that none of the headers will contain a +, - or numeric value, it would appear a pointless addition. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now