I created a main tcl file in a specified directory and I want to source another tcl file, which is not in a same directory of the main one.
Give the complete path to the Tcl file as argument to source.
Example: your main file (main.tcl) is in /, the other file (other.tcl) is in /foo/bar/.
source /foo/bar/other.tcl
As always, one must be careful with backslashes separating directories on the Windows platform. If the path is C:\foo\bar\, one must either escape the backslashes (C:\\foo\\bar\\ or {C:\foo\bar\}) or replace them with regular slashes, as in C:/foo/bar/. If the path is relative to the current directory, one can side-step the issue by using file join foo bar.
Documentation: filename, source
Related
My SSIS Package takes gpg file rather then text file i have puts file "*.txt" file in Files. any help will be appreciated.
This is expected, documented behavior. From MSDN:
Use wildcard characters (*) to specify the files to include in the
collection. For example, to include files with names that contain
“abc”, use the following filter: *abc*.
When you specify a file name extension, the enumerator also returns
files that have the same extension with additional characters
appended. (This is the same behavior as that of the dir command in the
operating system, which also compares 8.3 file names for backward
compatibility.) This behavior of the enumerator could cause unexpected
results. For example, you want to enumerate only Excel 2003 files, and
you specify "*.xls". However, the enumerator will also return Excel
2007 files because those files have the extension, ".xlsx".
You can use an expression to specify the files to include in a
collection, by expanding Expressions on the Collection page, selecting
the FileSpec property, and then clicking the ellipsis button (…) to
add the property expression. For more information about dynamically
selecting specified files, see SSIS–Dynamically set File Mask :
FileSpec
Try using *txt instead of *.txt so it doesn't treat "txt" as an extension and include files that end in ".txt.gpg"
I need to find the path of the target file pointed by a symbolic link in tcl. ie. if C:\temp\link is a symbolic link file pointed to the target C:\bin\sub\sub1\originalfile , how can we find the path C:\bin\sub\sub1\originalfile from the symbolic link file C:\temp\link using Tcl?
i used
set item "C:\temp\link"
file readlink $item
But it returned the following error
could not readlink "C:/temp/link": not a directory
Can anyone help?
There's a trick to handle this problem. It is introduced by the Tcler's Wiki: https://wiki.tcl-lang.org/page/file+normalize, by just appending /something at the end of the path of your symbol link file.
Below I post their original words:
Resolving symlinks in the last component of a path
To resolve symlinks
in a path's final component (i.e., the target file or directory name
itself) you can use the following trick: add /something to the path
before normalizing it then strip the extra component away with file
dirname.
For example,
set resolvedArgv0 [file dirname [file normalize $argv0/___]]]
dbohdan 2015-05-12: This trick was implemented by AK in Tclssg's main > procedure and I thought it deserved wider exposure. The credit is all AK's.
PYK 2015-05-12: This technique is also employed in main script.
I am trying to write a batch file so I can use TortoiseHg Annotate from the IDE I'm using (VDF Studio). The IDE provides the file name in lowercase, but TortoiseHg requires the file name to be properly cased (e.g. the file could be stored as 'C:\File.txt', so TortoiseHg will not recognize 'c:\file.txt').
My batch file looks something like this:
thg annotate %1
I need some way to replace %1 (the given file) with a file name having proper casing.
Use "%~f1", instead of %1.
See the documentation of those »special« expansions in help for (near the end).
I want to use the SSIS Package Configuration to change the path of several flat file destinations, but only the path, not the filename. Basically I have alot of flat files going to the same directory, but each has it's own name. Unfortunately the property on the flat file object includes both the filename and directory as one string. I would like to set it up so it is easy to change the directory for all of these, but where they still have their own unique filename.
Any ideas? Can this be done somehow with expressions?
Yes, can be done with Expressions.
Define a package variable for Path
Define an expression for ConnectionString with #[User:Path] + "\filename"
Use a package config to define the variable (or on command line)
I don't have SSIS on this PC so no screenies, sorry. Check this and this though
I am creating a Zip file from a folder (and subfolders). it works fine and creates a new .zip file also but I am having an issue while using glob.glob. It is reading all files from the desired folder (source folder) and writing to the new zip file but the problem is that it is, however, adding subdirectories, but not adding files form the subdirectories.
I am giving user an option to select the filename and path as well as filetype also (Zip or Tar). I don;t get any problem while creating .tar.gz file, but when use creates .zip file, this problem comes across.
Here is my code:
for name in (Source_Dir):
for name in glob.glob("/path/to/source/dir/*" ):
myZip.write(name, os.path.basename(name), zipfile.ZIP_DEFLATED)
myZip.close()
Also, if I use code below:
for dirpath, dirnames, filenames in os.walk(Source_Dir):
myZip.write(os.path.join(dirpath, filename) os.path.basename(filename))
myZip.close()
Now the 2nd code taks all files even if it inside the folder/ subfolders, creates a new .zip file and write to it without any directory strucure. It even does not take dir structure for main folder and simply write all files from main dir or subdir to that .zip file.
Can anyone please help me or suggest me. I would prefer glob.glob rather than the 2nd option to use.
Thanks in advance.
Regards,
Akash
Glob by design does not expand into subdirectories. It follows UNIX style path rules and expansions see the documentation for fnmatch for more information. If you want to get at the subdirectories you need to add it to the path. This example will get everything at one level down.
for name in (Source_Dir):
for name in glob.glob("/path/to/source/dir/*/*" ):
myZip.write(name, os.path.basename(name), zipfile.ZIP_DEFLATED)
myZip.close()
Doug Hellman has an excellent discussion here. If you are not using the pattern features of glob (like *.txt for all text files or *[0-9].txt for all text files that have a number before the extension) then I think your os.walk solution is better