Real directory name of a file path?
How do I find the normalized directory name of a path?
For example, when you cd to a directory you get what ever was in the cd command, not the real directory name.
See:
mac $ ls -l co
lrwxr-xr-x 1 mac staff 15 Aug 9 19:38 co@ -> /Users/mac/cons
mac $ cd co
mac $ pwd
/Users/mac/co
mac $ cd .
mac $ pwd
/Users/mac/co
mac $ cd ..
mac $ pwd
/Users/mac
mac $ cd cons
mac $ pwd
/Users/mac/cons
mac $ ls -ld .
drwxr-xr-x 31 mac staff 1054 Aug 9 12:12 ./
mac $ pwd
/Users/mac/cons
mac $
I this example, I want /Users/mac/cons not /Users/mac/co
Robert
My results from /bin/pwd are different.
Found out about the -P option to pwd command. There is also the set -P which effects the pwd result. see man pwd and help pwd and help set
something so simple is so complicated.
Thanks for the function. Pointed out a bug in the script I am working on. I am not checking the user passed me a directory path. Could be a file.
mac $ cd co
/Users/mac/co
mac $ /bin/pwd
/Users/mac/cons
mac $ PWD="" /bin/pwd
/Users/mac/cons
mac $ settings
mac $ pwd
/Users/mac/co
mac $ man pwd
mac $ pwd -P
/Users/mac/cons
mac $ pwd -L
/Users/mac/co
mac $ cd /USERS/MAC/CO
/USERS/MAC/CO
mac $ pwd
/USERS/MAC/CO
mac $ pwd -P
/Users/mac/cons
mac $ pwd -L
/USERS/MAC/CO
mac $ /bin/pwd
/Users/mac/cons
---------- env
MANPATH=/sw/share/man:/usr/share/man:/usr/local/share/man:/usr/X11R6/man:/sw/lib /perl5/5.8.6/man
TERM_PROGRAM=Apple_Terminal
TERM=xterm-color
SHELL=/bin/bash
PERL5LIB=/sw/lib/perl5:/sw/lib/perl5/darwin
TERM_PROGRAM_VERSION=133-1
OLDPWD=/USERS/MAC
USER=mac
__CF_USER_TEXT_ENCODING=0x3E8:0:0
PATH=/sw/bin:/sw/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/Developer/Tools:/usr/X11R6/ bin
XML_CATALOG_FILES=file:///Library/DTDs/catalog file:///etc/xml/catalog
PWD=/USERS/MAC/co
EDITOR=/usr/bin/pico
PS1=\u \$
PS2=additional input:
SHLVL=1
HOME=/Users/mac
INFOPATH=/sw/share/info:/sw/info:/usr/share/info
DISPLAY=:0.0
SECURITYSESSIONID=603760
_=/usr/bin/env
--------- set
BASH=/bin/bash
BASH_VERSINFO=([0]="2" [1]="05b" [2]="0" [3]="1" [4]="release" [5]="powerpc-apple-darwin8.0")
BASH_VERSION='2.05b.0(1)-release'
Similar Messages
-
Obtaining file name from the file path given
hi,
how to obtain file name from the file path givenHi bharath,
1. PC_SPLIT_COMPLETE_FILENAME
2.
DATA : path LIKE pcfile-path.
DATA : extension(5) TYPE c.
path = filename.
CALL FUNCTION 'PC_SPLIT_COMPLETE_FILENAME'
EXPORTING
complete_filename = path
* CHECK_DOS_FORMAT =
IMPORTING
* DRIVE =
extension = extension
name = name
* NAME_WITH_EXT =
* PATH =
EXCEPTIONS
invalid_drive = 1
invalid_extension = 2
invalid_name = 3
invalid_path = 4
OTHERS = 5
regards,
amit m. -
How to get immediate parent directory name of a file
Hi,
I have file Object that points to a file. I want to know how I can get just the name of the parent immediate to the file For example, if the path of this file is, c:\\ProgramFiles\first\second\third\myFile.txt
In the above, how can I obtain the last directory in which myFile.txt resides ?
Thanks
SangeethaFile myFile = new File("c:\\ProgramFiles\\first\\second\\third\\myFile.txt");
File parentFile = myFile.getParentFile();
String parentDirectory = parentFile.getName();
System.out.println("Parent directory is "+parentDirectory);Here's the explanation...
1) New File is created
2) File.getParentFile returns the immediate parent of the current File, which happens to be a directory.
3) File.getName() returns the name of the File, without the entire directory structure.
Hope this helps :)
Simon -
Dynamic directory name in Receiving File adapter
Hi,
In File to File senario, In receiving system i want to create directory name dynamically. In my mapping there is a field called name, the directory name in the receiving system will be value in the name field. Any one can help me how to do this one...
Thanks
RaoHello,
Please follow the below to achieve the same.
input - Store number,
UDF
String dynaname = input;
DynamicConfiguration conf = (DynamicConfiguration) container
.getTransformationParameters()
.get(StreamTransformationConstants.DYNAMIC_CONFIGURATION );
DynamicConfigurationKey key = DynamicConfigurationKey.create(
"http://sap.com/xi/XI/System/File","FileName");
conf.put(key,dynaname);
return "";
UDF mapping
Source[input] -
> UDF --> Rootnode of target structure.
Hope it helps.
best regards,
raj. -
Getting file name from a file path
Hello
I have got a String called filePath and it holds: "C:\Documents and Settings\paul\MyDocuments\nihtd.txt".
What I want do is to have another String variable called fileName that will use the 'filePath' variable to return the name on the file (that been "nihtd.txt" for the example given) but it must work with any file path for any file type.
Can anyone help? I have tried various ways but with no success.
Many thanks
PaulHmm, I just ran across another distinction between doing this by creating a File object as opposed to doing this by analysing the String: performance.
I always thought that creation of file objects is relatively cheap, since the Filesystem is not actually accessed when you create a new File instance. Apparently that is not true, at least not if you are on Windows and the file is on another server. Something like new File(\\server\share\file.txt) will create network traffic on Windows. So if you only meant to use the File class for parsing text, you might want to think again.
I would be interested to know how the FileSystem class is implemented on different platforms. Do you know where I can read up on that?
Cheers, HJK -
Retrieve file name from full file path
I am trying to retrieve a file name from a path (ex. c:\temp\tes.txt) using the following code, but it is given me an error of "The method split(String) in the type String is not applicable for the arguments (char).
{code}
String filepath = item.getName();
String[] buf = filepath.split('/');
String filename = buf[buf.length-1];
{code}
I tried to use double quote instead of single quote, but it is not returning anything.
{code}
String[] buf = filepath.split("/");
{code}
Anyone knows why? Thanks.How is this related to JDBC?
Anyway, is the path separator actually a forward slash? Isn't it a backward slash?
If you're using Apache Commons FileUpload (which I guess, the 'item.getName()' is recognizeable), then just read their FAQ: [http://commons.apache.org/fileupload/faq.html#whole-path-from-IE]. -
Deriving file path in communication channel depending on environment
We have received this request:
======begin request======
As you know transporting communication channels is a tedious affair
that consists of exporting and importing objects, manual steps to
modify the communication channel for the target system and then
activation. The process of manual modification of the communication
channel after it has been transported is particularly subject to human
error.
Could you please investigate using dynamic/logical names for such
things as:
Directory names
Filenames
Any thing else that can be derived dynamically, or set logically.
======end request======
An example would be a directory path in a file adapter:
in dev: <drive>/dev
in prod: <drive>/prd
We don't want to reconfigure the channel on transport. Value mapping
is not an alternative as we would have to maintain a table anyway and
use a custom function to derive. Dynamic Configuration in a map
requires a custom function and lack of flexibility. Adapter Specific
Message Attributes don't really help.
Is there some way environment variables can be accessed and configured in a communication channel?Hey Dave,
reconfiguring Adapters after Integration Directory objects transport is a necessary step, since the addresses/ports of production environments will almost always be different.
Nevertheless, you will need to manually reinsert the path information in Prod File adapter, and there you could use "prod" instead of "dev".
A possible workaround to make it a little more "automatic" would be to refer to the Business System name in the File path, using variable substitution. In this case, for example, use the variable "dir" in the variable substitution table, refering to the property "message:receiver_service" (without quotes), and in the path field, use something like "/%dir/" (also, without quotes).
Regards,
Henrique. -
FM for browsing the directory name in presentation server
Hi All,
Can somebody give me the FM for browsing the directory name (not the file name) in the presentation server so that the path comes automatically in the parameter.
Thanks in advance.
Regards,
Arun MohanPlease see the following program. This will give you what you need.
report zrich_0001 .
parameters: p_path type localfile.
at selection-screen on value-request for p_path.
data: path_str type string.
call method cl_gui_frontend_services=>directory_browse
exporting
window_title = 'Select Directory'
changing
selected_folder = path_str
exceptions
cntl_error = 1.
call method cl_gui_cfw=>flush
exceptions
cntl_system_error = 1
cntl_error = 2.
p_path = path_str.
Regards,
Rich Heilman -
hai ,
good morning. i would like to know is it possible than when i open a text file to be plotted as a graph (from pop up directory) the plot name to be same as the file name which i opened. for example when i open file (test1) to be plotted. the plot name on the graph will be test1. the file name is not fixed. thanks
regards
shamaranYou need to get the file name from the file path and give as a plot name.See the attached example.
Message Edited by Baji on 11-06-2009 12:33 PM
Balaji PK (CLA)
Ever tried. Ever failed. No matter. Try again. Fail again. Fail better
Don't forget Kudos for Good Answers, and Mark a solution if your problem is solved.
Attachments:
Plot name.vi 23 KB -
Our project is using TestStand 2012 SP1.
We are using reportgen_txt.seq. and SequentialModel(.seq).
My goal is to save report files to a specific directory only when I run my Self_Test.seq.
I'm attempting to use Configure >> Report Options >> Generate Report File Path.
Setting in "Report Options" dialog >> "Generate Report File Path" tab:
Type Model: Sequential
File Name/Directory Options: Specify Report File Path by Expression
This is the expression that I'm using:
"<ClientFileName>" == "Self_Test" ? "C:\\Reports\\Self-test\\<ClientFileName>_Report[<UUT>][<FileTime>][<FileDate>]<Unique>.<FileExtension>" : "C:\\Reports\\<UUT>\\<ClientFileName>_Report[<UUT>][<FileTime>][<FileDate>]<Unique>.<FileExtension>"
The statment passes syntax check with "no errors".
Running Self_Test.seq using the sequence editor, the report file always goes to path in Red.
Is there a method to accomplish this?
Solved!
Go to Solution.Hi Leroy/jigg,
You are correct that the expression itself is evaluated before the Macro strings are resolved, so this approach won't work. The macros are evaluated using modelsupport2.dll (DetermineReportFilePathNameExprEx function), which first evaluates the expression before resolving the macros. For implementing a custom report file path expression for a particular client file, I would recommend overriding the ReportOptions callback, then programatically setting the report path expression, using an expression such as:
Parameters.ReportOptions.ReportFileSequentialModelExpression = "\"MyCustomLocation\\<ClientFileName>_Report[<FileTime>][<FileDate>].<FileExtension>\""
Note the use of double quotes since the field is an expression field. This approach will also allow you to use logic in the callback to change the report file path string using TestStand flow control steps.
Al B.
Staff Software Engineer - TestStand
CTA/CLD -
Pg Number, File path and date automatically printed?
Is there a way to automatically print the page number, complete file path and date at bottom of each page (set to landscape)?
Thanks!Thanks Carlos,
It looks like the work72a would work if we were using macs, but we're not...
And there is NO WAY my boss will pay $999 for the other one, even if it did work.
So, now I'm open to other suggestions. We have hundreds of clients that we do work for, and our jobs are organized in folders for each client. A lot of clients with the same name but different locations (ie., Fox Meadow OH, Fox Meadow TX), and each has a different folder. The files are named by dept and year (ie., 2012 Glass, 2012 Art). We often access old files (which, there are thousands of, because they have been organized this way for years.) We need to have the client folder on the page along with the file name (hence the file path).
The script that Carlos created is great, but there are too many steps. Open the script, change location and select info to be displayed (3 steps), close script. There are days we access 50 jobs and the script just added 5 plus steps to each job.
Is there a way to use a hot key run a script that will place the info when and where we need it and auto close the script? Or is there a way to display the full path (in the Illustrator tab?) where we can see which folder the file is in and we will manually type the folder? Or does anyone have another suggestion? -
Hi,
I have a solution that used to contain one SharePoint 2010 project. The project is named along the following lines:
<Company>.<Product>.SharePoint - let's call it Project1 for future reference. It contains a number of features which have been named according
to their purpose, some are reasonably long and the paths fairly deep. As far as I am concerned we are using sensible namespaces and these reflect our company policy of "doing things properly".
I first encountered the following error message when packaging the aforementioned SharePoint project into a wsp:
"The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters."
I went through a great deal of pain in trying to rename the project, shorten feature names and namespaces etc... until I got it working. I then went about gradually
renaming everything until eventually I had what I started with, and it all worked. So I was none the wiser...not ideal, but I needed to get on and had tight delivery timelines.
Recently we wanted to add another SharePoint project so that we could move some of our core functinality out into a separate SharePoint solution - e.g. custom workflow
error logging. So we created another project in Visual Studio called:
<Company>.<Product>.SharePoint.<Subsystem> - let's call it Project2 for future reference
And this is when the error has come back and bitten me! The scenario is now as follows:
1. project1 packages and deploys successfully with long feature names and deep paths.
2. project2 does not package and has no features in it at all. The project2 name is 13 characters longer than project1
I am convinced this is a bug with Visual Studio and/or the Package MSBuild target. Why? Let me explain my findings so far:
1. By doing the following I can get project2 to package
In Visual Studio 2010 show all files of project2, delete the obj, bin, pkg, pkgobj folders.
Clean the solution
Shut down Visual Studio 2010
Open Visual Studio 2010
Rebuild the solution
Package the project2
et voila the package is generated!
This demonstrates that the package error message is in fact inaccurate and that it can create the package, it just needs a little help, since Visual Studio seems to
no longer be hanging onto something.
Clearly this is fine for a small time project, but try doing this in an environment where we use Continuous Integration, Unit Testing and automatic deployment of SharePoint
solutions on a Build Server using automated builds.
2. I have created another project3 which has a ludicrously long name, this packages fine and also has no features contained within it.
3. I have looked at the length of the path under the pkg folder for project1 and it is large in comparison to the one that is generated for project2, that is when it
does successfully package using the method outlined in 1. above. This is strange since project1 packages and project2 does not.
4. If I attempt to add project2 to my command line build using MSBuild then it fails to package and when I then open up Visual Studio and attempt to package project2
from the Visual Studio UI then it fails with the path too long error message, until I go through the steps outlined in 1. above to get it to package.
5. DebugView shows nothing useful during the build and packaging of the project.
6. The error seems to occur in
CreateSharePointProjectService target called at line 365 of
Microsoft.VisualStudio.SharePoint.targetsCurrently I am at a loss to work out why this is happening? My next task is to delete
project2 completely and recreate it and introduce it into my Visual Studio solution.
Microsoft, can you confirm whether this is a known issue and whether others have encountered this issue? Is it resolved in a hotfix?
Anybody else, can you confirm whether you have come up with a solution to this issue? When I mean a solution I mean one that does not mean that I have to rename my namespaces,
project etc... and is actually workable in a meaningful Visual Studio solution.Hi
Yes, I thought I had fixed this my moving my solution from the usual documents to
c:\v2010\projectsOverflow\DetailedProjectTimeline
This builds ok, but when I come to package I get the lovely error:
Error 2 The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters. C:\VS2010\ProjectsOverflow\DetailedProjectTimeline\VisualDetailedProjectTimelineWebPart\Features\Feature1\Feature1.feature VisualDetailedProjectTimeline
Now, the error seems to be related to
Can anyone suggest what might be causing this. Probably some path in an XML file somewhere. Here is my prime suspect!
<metaData>
<type name="VisualDetailedProjectTimelineWebPart.VisualProjectTimelineWebPart.VisualProjectTimeline, $SharePoint.Project.AssemblyFullName$" />
<importErrorMessage>$Resources:core,ImportErrorMessage;</importErrorMessage>
</metaData>
<data>
<properties>
<property name="Title" type="string">VisualProjectTimelineWebPart</property>
<property name="Description" type="string">My Visual WebPart</property>
</properties>
</data>
</webPart>
</webParts>
.... Unless I can solve this I will have to remove the project and recreate but with simple paths. Tho I will be none the wiser if I come across this again.
Daniel -
Hi, Im trying to get the whole path in my server, so i tried that with this following code
Get-ChildItem $sourceFolder -Recurse | ?{$_.PsIsContainer} |Get-Acl
But then, it showed me somtehing like this :
Get-ChildItem : The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.
I tried to find the solver everywhere and mostly they propose to change the path name, which is impossible, since I am working with my company server, and those folder have already there before i start to work here, then the other ask me to use robocopy,
but all of the trick just dont work
is there any way to solve this problem? thanksThere is no simple solution to this. And it is not a limitation of powershell itself, but of the underlying NTFS file system.
If the problem is that a folder with a name longer than 248 exists anywhere within your directory structure, you are hooped.
If the problem is that some fully qualified path names exceed 260 characters, then, in those cases, the solution already given is to create a psdrive partway up the path from the drive letter or server/share root of the path. Unfortunately, the output produced
will be relative to that psdrive and not to what is specified as the $sourcefolder.
unless you already know where those problematic paths are, you might consider trying to trap those errors and have your script figure out where it needs to create psdrives. You might then be able to calculate the equivalent path for each file or folder and
output that. the programming effort would be simpler to just created a psdrive for each folder encountered, however I expect that would be very inefficient.
Al Dunbar -- remember to 'mark or propose as answer' or 'vote as helpful' as appropriate. -
Problems with spaces in file or directory names and Word.exe
Hi
I'm trying to open a file with Word from my java aplication, and I have a problem with some file/directory names.
I have this
String cmd = "c:\\Program Files\\Microsoft Office\\Office10\\WINWORD.EXE" + " " + path;
try {
Runtime.getRuntime().exec(cmd);
} catch (Exception errorea){ }
Here is what happens:
if path is something like this: "c:\people\info.doc" , there's no problem, Word opens the document, but if path contains blank spaces somewhere, it doesn't work. For example:
path = "c:\Documents and Settings\info.doc"
path = "c:\Hi everybody\info.doc"
path = "c:\tests\test results.doc"
with the above examples it doesn't work :( Word tries to open "c:\Documents", "c:\Hi" or "c:\tests\test".
Can anyone help? thanx a lot ! : )Hint: use the variant Runtime.exec(String[] args).
Create a command array, with each token in a separate argument. The entire filename with spaces goes into one argument. -
Using a dialog window to select a name and directory to save the file
Hi there
I have a problem with the FILE_SAVE_DIALOG method or better with the windows that will be shown.
Before I save a file (e.g. PDF file) on the presentation server (the PC), I want to open a dialog window to have the option to give another directory and file name, under which I will save the file.
Therefore I use the method CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG. I found many information about this FILE_SAVE_DIALOG in this forum, but these tips didn't satisfy me.
The main problem is the FILE_FILTER. How to use this filter (is it a STRING?) properly, when I want to have a list in the dialog window? Nothing worked till now.
I use ERP 2005 with JAVA 1.4.1-07.
My Code:
DATA: fileName TYPE STRING,
path TYPE STRING,
workdir TYPE STRING,
user_action TYPE I,
encoding TYPE ABAP_ENCODING.
fileName = I_FILENAME.
path = I_PATH.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG
EXPORTING
WINDOW_TITLE = 'Save Adobe PDF file'
* WITH_ENCODING = 'X'
INITIAL_DIRECTORY = workdir
* DEFAULT_EXTENSION = '*.pdf'
DEFAULT_FILE_NAME = fileName
FILE_FILTER = '*.pdf'
PROMPT_ON_OVERWRITE = 'X'
CHANGING
FILENAME = fileName
PATH = path
FULLPATH = fullpath
USER_ACTION = user_action
FILE_ENCODING = encoding
EXCEPTIONS
CNTL_ERROR = 1
ERROR_NO_GUI = 2
NOT_SUPPORTED_BY_GUI = 3
others = 4.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
IF user_action <> CL_GUI_FRONTEND_SERVICES=>ACTION_OK.
EXIT.
ENDIF.
When I call this method with these parameters, I get the dialog window, but there is no filtering for PDFs.
I also tried the ideas with:
FILE_FILTER = 'Adobe files (*.pdf)|(*.pdf)'
and so on. But nothing made the dialog window work properly, even the selection list didn't show the right content to select.
Who can help with this method SAVE_FILE_DIALOG?
Thanks
FrowinHI,
check this program.
<b>
report ZTEST2.
data: file type string,
path type string,
file_path type string.
data: itab type standard table of cskt.
start-of-selection.
SELECT * FROM cskt INTO TABLE itab.
call method cl_gui_frontend_services=>file_save_dialog
exporting
FILE_FILTER = '*.PDF'
changing FILENAME = file
path = path
fullpath = file_path.
check not file_path is initial.
call method cl_gui_frontend_services=>gui_download
exporting filename = file_Path
WRITE_FIELD_SEPARATOR = 'X'
changing data_tab = itab.
</b>
REgards,
Maybe you are looking for
-
10.6.8 update won't install gets half way through then just freezes spinning beach ball for 4 hours any ideas y. Tried and restarted 3 times already does the same thing each time have to hold down the power button to restart. Anyone can help
-
Hi all, When I view this PDF in Adobe Acrobat 9.3.0 (Windows), I see no problem. When I open the PDF in Photoshop, a white rectangle next to the white square at the bottom left corner appears. Anyone familiar with this phenomenon? Any idea what's wro
-
BAPI_PO_CREATE1 Strange Problem. Plz Help.
Dear all, we have just created program to create import Purchase order ,using BAPI_PO_CREATE1 to create several PO's from a text file. Program is working fine, what I observe , when I am trying to edit po condition value through transaction ME22N, a
-
How to add a rescue email to an existing apple ID ?
how to add a rescue email to an existing apple ID ?
-
I just got my MacBook Pro with retnia yesterday. Its my first mac. I am extreamly unknowlagebale about macs. Last night when I went to bed I plugged it in to charge. This morning when I went to get on it, it was incredibly hot, both the top and botto