in windows SAS, how to read the file loaded recently in particular path - windows

in windows SAS, how to read the file loaded recently in particular path.
as i am accing from a path having lot of files , so it should pick a file having the latest data loaded in that path

If you have non-SAS files in the destination directory, you can pipe a command such as dir <your directory> /od /b to a data as illustrated in this question.
If all the files are SAS datasets, create a libref to the directory and try
proc sql noprint;
select
memname,
crdate
into
:newestdata,
:createdate
from
dictionary.tables
where
libname=upcase("<your libname>")
having
crdate=max(crdate);
quit;
%put &newestdata;
%put &createdate;
Unless there are data sets which have the exact same creation time stamp, the &newestdata and &createdate macro variables should contain the name and creation date of the latest data set.

Related

Updating "Date Created" after copying files

I have recently used iCloud for Windows (10) to download all pictures from iCloud onto my local machine. I then wanted to create a backup so I copy-pasted all (15'000) pictures onto an external hard disk.
I noticed that because of the copy-paste action, the "Date Created" has -- in hindsight obviously -- been changed from the date that the picture was taken to the date / time of the copy action.
Since the copy-action and before I noticed the change of date, I have put many hours into putting pictures in subfolders, etc. I would now like to put the original date/time back into the metadata.
My idea is to make a dirlisting of the iCloud original archive, returning filename, md5 hash, and Date Created. I then want to write a script (Powershell?) to find the matching file in my subfolders, and update the date.
A few questions:
Does this seem like the best approach?
Is there a better way to copy photo's in the future, keeping the original Date Created?
Any help into the right direction whether this is a good idea with Powershell, would be greatly appreciated.
Manually changing timestamps using PowerShell
To change the Date Created, Date Modified, and Date Accessed file properties using PowerShell, I'd recommend checking out this website here. It explains how to change the Date Created/Modified/Accessed file properties for a single file, for all files in a given folder, or even for a folder itself. For example:
For a single file:
To set the date created time for "filename.txt" to 5 December 2012 at, say, 9:57:05 PM, you'd write:
(Get-Item "C:\Users\Path_to_file\filename.txt").creationtime=$(Get-Date "05/12/2012 21:57:05")
Similarly, to set the date modified, you'd write:
(Get-Item "C:\Users\Path_to_file\filename.txt").lastwritetime=$(Get-Date "05/12/2012 21:57:05")
and for date accessed time:
(Get-Item "C:\Users\Path_to_file\filename.txt").lastaccesstime=$(Get-Date "05/12/2012 21:57:05")
You can event set properties to other properties. For example:
To set the date created equal to the date modified, you'd write:
(Get-Item "C:\Users\Path_to_file\filename.txt").creationtime=$(Get-Item "C:\Users\Path_to_file\filename.txt").lastwritetime
For all files in a folder named "Test":
Get-ChildItem -force 'C:\Users\Path_to_folder\Test\' * | ForEach-Object{$_.CreationTime = ("3 August 2019 17:00:00")}
Get-ChildItem -force 'C:\Users\Path_to_folder\Test\' * | ForEach-Object{$_.LastWriteTime = ("3 August 2019 17:10:00")}
Get-ChildItem -force 'C:\Users\Path_to_folder\Test\' * | ForEach-Object{$_.LastAccessTime = ("3 August 2019 17:10:00")}
Note that the -force parameter ensures that hidden files are also included. Also, keep in mind that if you want to change each picture's timestamps to that of its own corresponding image (i.e, if you want to intelligently automate the process), you'll need to write a script that takes care of each separate case.
Copy files while preserving timestamps (and more)
The simplest tool to use is Windows' own, built-in tool: robocopy. See Microsoft's documentation on the robocopy command here. You just run the program via the command prompt (with administrator privileges).
For your needs, suppose you have images and videos in their original form (the ones that have all the correct timestamps, etc.) in the folder "Original", located at "C:\Users\Person\Desktop\Original", and you'd like to copy all those images and videos to a folder located on your external hard drive, at "D:\Pictures\Copied". The following command would probably work best:
robocopy "C:\Users\Person\Desktop\Original" "D:\Pictures\Copied" *.* /e /copy:DAT /dcopy:DAT /mt:16 /j /xjd /xa:s /r:1 /w:0 /log:"filename_path.txt"
Each argument is explained in detail on Microsoft's documentation page for robocopy, but I'll explain them here too.
The 1st argument specifies the path to the source folder. Please note that there are no trailing backslashes! If you include a backslash at the end, robocopy won't understand the input.
The 2nd argument specifies the path to the destination folder.
The 3rd argument can actually be multiple arguments. Here, the *.* specifies the file or files to be copied. Since wildcard characters (* or ?) are supported, *.* matches all files in the source directory (i.e., everything will be copied). *.* is the default parameter, so if you want all files to be copied, you don't even need to specify this parameter. If you want to copy, say, all files that end in .jpg, you'd write *.jpg. Or, if you want to copy, say, just two files file1.jpg and file2.mp4, you'd write those out explicitly, one after each other, as such robocopy "C:\Users\Person\Desktop\Original" "D:\Pictures\Copied" file1.jpg file2.mp4 /e /copy:DAT /dcopy:DAT /mt:16 /j /xjd /xa:s /r:1 /w:0 /log:"filename_path.txt".
The 4th argument /e copies subdirectories. This option automatically includes empty directories.
/copy:DAT specifies which file properties to copy. Here, D, A, and T means that the file's Data, Attributes, and Time Stamps properties will be copied. Refer to robocopy's documentation for more details.
/dcopy:DAT same as /copy:DAT except for folders.
/mt:16 creates multi-threaded copies with 16 threads. You can specify an integer between 1 and 128.
/j copies using unbuffered I/O (recommended for large files).
/xjd excludes junction points for directories.
/xa:s excludes "System" files.
/r:1 specifies the number of retries on failed copies. Here, it's set to 1. The default value is 1,000,000 (one million retries)!
/w:0 specifies the wait time between retries, in seconds. Here, it's set to 0, so 0 seconds are spent waiting.
/log:"filename_path.txt" writes the status output to the log file.

Location of the table space files?

How can I find the directory in which oracle stores it's table space files?
When I do: select * from dba_data_files; or select * from v$datafile; then I get some paths like that:
+DATA01/fu/datafile/bar_ts01_data.260.264360912
But what means +DATA01? And where is that exactly in the file system?
+DATA01/fu/datafile/bar_ts01_data.260.264360912
Yes this is correct file path. It means you use ASM disk.
After you login to OS with "grid" user [usually Oracle Grid Infrastructure installation user is named like that], run following command to browse files on ASM disk.
export ORACLE_HOME=/u01/app/11.2.0/grid --this is also usual installation dir, may differ on your case
export ORACLE_SID=+ASM
cd $ORACLE_HOME/bin
./asmcmd -p
ASMCMD>ls
+DATA01
+DATA02
ASMCMD>cd +DATA01
In that table, the file_name field should give the full path to the datafile.
Also, try select * from v$datafile; and that view should help as well.

Batch command XCOPY prompts me: Is the destination file or directory

When I run this file:
xcopy .\*.odt .\source.zip
I am prompted to specify what source.zip is:
xcopy .\*.odt .\source.zip
Does .\source.zip specify a file name
or directory name on the target
(F = file, D = directory)?
In my case when it find the .odt file to copy the file and place in the same directory but with new name source.zip. Is there approach to avoid the prompting since I always want destination to be a file not directory.
Any .odt file (being in .zip format in fact) is a binary file, see OpenDocument Document Representation
As a collection of several sub-documents within a package, each of which stores part of the complete document. This is the common
representation of OpenDocument documents. It uses filename extensions
such as .odt, .ott, .ods, .odp ... etc. The package is a
standard ZIP file with different filename extensions and with a
defined structure of sub-documents. Each sub-document within a package
has a different document root and stores a particular aspect of the
XML document. All types of documents (e.g. text and spreadsheet
documents) use the same set of document and sub-document definitions.
Therefore, you need to treat it as a binary file (read copy /?):
copy /B .\*.odt .\source.zip
Above command would work smoothly only if there will be only one file with extension .odt. Otherwise, it will prompt you for Overwrite .\source.zip? (Yes/No/All):. To stay on the safe side:
from command line for %G in (.\*.odt) do copy /B "%G" ".\source_%~nG.zip"
from a batch script for %%G in (.\*.odt) do copy /B "%%G" ".\source_%%~nG.zip"
%~nG (or in batch %%~nG) explanation: read Parameter Extensions.

CMD to pick up specific files using a wild card

I have a CMD script I have been working on that reads a folder that has 3 different files in it. They have names like the following:
File1_ddmmyyyy.txt
File2_ddmmyyyy.txt
file3_ddmmyyyy.txt
I can use * to identify the files but the next step that uses the file name (Launching an ETL program) requires that the full file path. It is unable to identify the file (is entered as: file3_*.txt Literally)
Does anyone have and ideas on how I can grab this file based on the Wildcard, then obtain the full name to use later?
Thanks
EDIT - Example-
There is one ETL File executable line that matches up with each of the files based on the file name. for example:
File1_ddmmyyyy.txt is matched with ETL file File1.tf.map (Based on the file name and ETL file name) it is a one to one match (3 files to load and 3 ETL files to load them)
DJENGINE -sc "Y:\FileLocation\%Year_Mo_Da%\File1*.txt"-tc Server="X";Database="Y";Table="dbo.File1" "Y:\MapLocation\File1.tf.xml" (FileName = File1_ddmmyyyy.txt)
DJENGINE -sc "Y:\FileLocation\%Year_Mo_Da%\File2*.txt"-tc Server="X";Database="Y";Table="dbo.File2" "Y:\MapLocation\File2.tf.xml" (FileName = File2_ddmmyyyy.txt)
DJENGINE -sc "Y:\FileLocation\%Year_Mo_Da%\File3*.txt"-tc Server="X";Database="Y";Table="dbo.File3" "Y:\MapLocation\File3.tf.xml" (FileName = File3_ddmmyyyy.txt)
In the executable line of code for the ETL program instead of referencing the actual file name (Needed to run) it is trying to run File1*.txt Not filling in the variable.
My only thought would be since I have only 3 files and three ETL files that match base on the root file names I can place each of the files full names in a variable prior to this then use each of them in the executable ETL lines.
Not sure if this would work or how to do it. Let me know if this helps.
Hmm - started off clear as mud.
Then Taz arrived with his mixmaster on Turbo...
What congeals from this appears to be:
There's a directory "Y:\FileLocation\yyyy_mm_dd which contains 3 text files FileNddmmyyyy.txt
where dd is day number, mm month number, yyyy 4-digit year number and N will be 1..3.
The requirement from there is to build an appropriate command using the template
DJENGINE -sc "Y:\FileLocation\yyyy_mm_dd\FileN_ddmmyyyy.txt" -tc Server="X";Database="Y";Table="dbo.FileN" "Y:\MapLocation\FileN.tf.xml"
where dd,mm,yyyy,N have the same meanings, for N=1..3
#ECHO OFF
SETLOCAL
SET "yyyymmdd=%1"
IF NOT DEFINED yyyymmdd for /f "skip=1 delims=" %%x in ('wmic os get localdatetime') do set yyyymmdd=%%x&GOTO gotdate
:gotdate
SET "yyyymmdd=%yyyymmdd:~0,8%"&SET "yyyy=%yyyymmdd:~0,4%"&SET "mm=%yyyymmdd:~4,2%"&SET "dd=%yyyymmdd:~6,2%"
FOR %%a IN (1,2,3) DO ECHO(DJENGINE -sc "Y:\FileLocation\%yyyy%_%mm%_%dd%\File%%a_%dd%%mm%%yyyy%.txt" -tc Server="X";Database="Y";Table="dbo.File%%a" "Y:\MapLocation\File%%a.tf.xml"
GOTO :EOF
In the absence of any information about where yyyymmdd come from, the above should fill in the values for today.
If the procedure is provided with a parameter in the format yyyymmdd like this:
thisbatch 20140726
then the procedure will generate lines for July 26th 2014 (note that the value provided here is not checked for validity)
The required DJENGINE commands are merely ECHOed for testing purposes. After you've verified that the commands are correct, change ECHO(DJENGINE to DJENGINE to actually execute the program on the files. This presumes that DJENGINE is an executable, not a batch procedure.

Using MakeCab.exe & .ddf file (i.e. using directive file) how to specify destination cab filename?

I have decided to use makecab.exe for my requirement to create cab files in my application.
http://msdn.microsoft.com/en-us/library/bb417343.aspx#microsoftmakecabusersguide
And I need to store files as per given path whether relative or absolute inside cab and extract files with original path preserved. So I will be using directive file for this and give that input to makecab command.
windows command promt zip/compress directory
But the cab output is stored in folder Disk1\1.cab.
Please help me to know how can I specify a desired cab filename as destination (I will take cab file name from user input)?
Also, is it possible to append more files to existing cab file in second run of makecab command?
Finally found the solution.
You can set following two variables in the directive file which will identify destination path and name of cab file:
DiskDirectoryTemplate=template [Output directory name template; * is replaced by disk number]
CabinetNameTemplate=template [Cabinet file name template; * is replaced by Cabinet number]
Description from Microsoft MakeCAB User's Guide
DiskDirectoryTemplate=template
Set the output directory name template. One directory is created for
each disk of the layout.
Default: .Set DiskDirectoryTemplate=DISK* ; Default is DISK1, DISK2,
etc.
As MakeCAB processes a directive file, it will create one or more
disk "images". Rather than using some specific disk format, however,
MakeCAB simply creates one subdirectory for each disk and places the
files for each disk in the appropriate directory. If a * exists in
this variable, then it is replaced with the disk number. If no * is
specified, then all files are placed in the single directory specified
by this variable.
This variable is used only if no variable DiskDirectoryn exists for
disk n.
Examples:
.Set DiskDirectoryTemplate=C:\EXCEL6\DISK* ; Put files in separate dirs
.Set DiskDirectoryTemplate=C:\EXCEL6 ; Put all files in C:\EXCEL6
.Set DiskDirectoryTemplate= ; Put all files in current dir
CabinetNameTemplate=template
Sets the cabinet file name template.
Default: .Set CabinetNameTemplate=*.CAB ; 1.CAB, 2.CAB, ...
This template is used to construct the file name of each cabinet. The *
in this template is replaced by the cabinet number (1, 2, etc.). This
variable is used only if no variable CabinetNamen exists for cabinet
n.
NOTE: Be sure that the expanded cabinet name does not exceed the
limits for your file system! For example, if you used "CABINET*.CAB",
and MakeCAB had to create 10 or more cabinets, then you would have
cabinet names like CABINET10.CAB, which is 9.3, which is an invalid
name in the FAT file system. Unfortunately, MakeCAB would not detect
this until it had already created 9 cabinets!
Examples:
.Set CabinetNameTemplate=EXCEL*.DIA ; EXCEL1.DIA, EXCEL2.DIA, etc.
.Set CabinetNameTemplate=*. ; 1, 2, 3, etc.
In addition, when files are split across cab (in case if cabinet size exceeds its limit size) then you can set subsequent cabinet filenames also using variable CabinetNamen:
CabinetNamen=filename [Cabinet file name for cabinet number n]
CabinetNamen=filename
The cabinet file name for the specified cabinet.
Default: ; By default none of these variables are defined
If this
variable is not defined for a particular disk, then MakeCAB uses the
CabinetNameTemplate to construct the cabinet name.
Example:
.Set CabinetName2=test2.cab
If you know exactly where your source files exist, you can generate a file list from the directory:
dir C:\FolderName /s /b /a-d > c:\temp\files.txt
Then use the files.txt file to create the cab file.
makecab /d CabinetName1=test.cab /D DiskDirectoryTemplate=C:\temp /f c:\temp\files.txt
The above command will generate a test.cab file in your C:\Temp folder using the file list generated earlier.
Additional helpful reference:
Microsoft Cabinet Reference. and
makecab.exe details.

Resources