In our inbound directory we have the following file structure.
abc.csv.timestamp
abc.csv.timestamp
abc.csv.timestamp
I want to find the most recent file in the directory and MOVE to another directory.
However i want to pass the file pattern abc.csv.* as a string to the command.
Any pointers ?
Related
I have very little experience with the command line and I'm trying to do something very complicated (to me).
I have a directory with A LOT of subfolders and files in them. All file names contain the parent folder name, e.g.:
Folder1
data_Folder1.csv
other_file_Folder1.csv
Folder2
data_Folder2.csv
other_file_Folder2.csv
In another folder (all in one directory), I have a new version of all the data_FolderX.csv files and I need to replace them in the original folders. I cannot give them another name because of later analyses. Is there a way to replace the files in the original folders with the new version, in the command line?
I tried this Replacing a file into multiple folders/subdirectories but didn't work for me. Given that I have many .csv files in the derectories, I don't want to replace them all, so I don't think I should do it based on the file extension. I would also like to note that the name "FolderX" contains several other _, so in principal, I want to replace the .csv file starting with data in the FolderX.
Can anyone help?
Thanks in advance!
I'm trying to build a service in go that writes to a file with reference to the root directory as opposed to the working directory.
For example, my working directory is /Users/joe/dev/go and I want to create a file test.txt in the directory /Users/joe/generatedFiles/. I want to write a file /Users/joe/generatedFiles/test.txt.
I can't write to this directory unless the folder generatedFiles is created else I get the error "no such file or directory."
To do this I plan on calling os.MkdirAll("Users/joe/generatedFiles/", os.ModePerm) but this isn't giving me the expected functionality. Instead, it creates the folder: /Users/joe/dev/go/Users/joe/generatedFiles/.
I've also tried calling os.MkdirAll("/Users/joe/generatedFiles/", os.ModePerm) with a slash at the beginning of the file path but this is doing nothing. What can I do to write to a file in reference to the root directory?
Use an absolute path to specify the directory:
os.MkdirAll("/Users/joe/generatedFiles/", os.ModePerm)
Note the leading /.
I'm trying to replace a file once the OMC is set.
This code sets my "OMC" to the specific country code
Once this is done, I want to copy an xml file from a specific directory (this is just a random xml file I've edited with different parameters) and replace the original file in the OMC directory once the following script has detected the OMC.
In other words, to use an example, following this code I need to replace a file I have, let's just say, "temp/test.xml" to the directory "ABC/test.xml".
The "ABC/" directory will be the one the following the country code selected below.
getprop ro.boot.bootloader >> /tmp/BLmodel
ACTUAL_CSC=`cat /efs/imei/mps_code.dat`
ACTUAL_OMC=`cat /efs/imei/omcnw_code.dat`
SALES_CODE=`cat /system/omc/sales_code.dat`
sed -i -- "s/CSC=//g" /tmp/aroma/csc.prop
NEW_CSC=`cat /tmp/aroma/csc.prop`
buildprop=/system/build.prop
Given the following text file which contains a list of directories, how would you automatically generate the file path if it doesn't exist.
apache/bin/
apache/build/
apache/error/include
apache/htdocs/images/
apache/icon/small
python/bin
python/include/python2.7
lib/pkconfig
lib/python2.7/bsddb/test
lib/python2.7/compiler
lib/python2.7/ctypes/macholib
lib/python2.7/ctypes/test
For example, from the root/start directory, if the line reads apache/bin/, I want to check if the folder apache exists, if it doesn't, then I create it.
After that I want to cd into it, check if the file bin exists, if it doesn't then I create it. Then before moving into the new line, I want to move back into the root directory (i.e. move up two levels).
How would I accomplish this in Bash?
I am looking for a way to add File(s) to an existing directory that has a random name as part of a Visual Studio Setup Project and I hoped someone might be able to help me solve this puzzle please.
I have been attempting to obtain the discovered path property of the directory using a Launch Condition; Unfortunately this method returns the full file path including the filename, which cannot be used as a directory property.
The directory in question takes the form [AppDataFolder]Company\Product\aaaaaaaaaaaa\
where aaaaaaaaaaaa is a random installation string.
Within the Launch Condition Setup I check for the directory's existence by searching for a file that would appear inside it,
Search Target Machine
(Name): File marker
Filename: sample.txt
Folder: [AppDataFolder]Company\Product\
Property: DIRFILE
Launch Condition
(Name): File marker exists
Condition: DIRFILE
In the Setup Project I add the file I wish to insert, with the details
Condition: DIRFILE
Folder: 'Installation folder'
Then in File System Setup I add a new folder entry for the random directory aaaaaaaaaaaa
(Name): Installation folder
Condition: DIRFILE
DefaultLocation: [DIRFILE]\..\ *Incorrect*
Property [DIRLOCATION]
As you can see the installer detects the existence of the marker file but, instead of placing my file at the same location, when using [DIRFILE] the installer would incorrectly try and insert it INTO the file;
This is because the file path was returned
[AppDataFolder]Company\Product\aaaaaaaaaaaa\sample.txt
where I instead need the directory path
[AppDataFolder]Company\Product\aaaaaaaaaaaa
Therefore I was wondering if it was possible to return the directory the file was found in from Search Target Machine (as opposed to the file location of the file), if I could extract the directory path by performing a string replace of the filename on the file location DIRFILE within the DefaultLocation field in File System Setup, or if perhaps there is even another method I am missing?
I'm also very interested in a simple solution for this, inside the setup project.
The way I did solve it was to install the files to a temporary location and then copy them to the final location in an AfterInstall event handler. Not a very elegant solution! Since it no longer care about the user selected target path I removed that dialog. Also I needed to take special care when uninstalling.
public override void OnAfterInstall(IDictionary savedState)
{
base.OnAfterInstall(savedState);
// Get original file folder
string originDir = Context.Parameters["targetdir"];
// Get new file folder based on the dir of sample.txt
string newDir = Path.GetDirectoryName(Context.Parameters["dirfile"]);
// Application executable file name
// (or loop for all files on the path instead)
string filename = "ApplicationName.exe";
// Move or copy the file
File.Move(Path.Combine(originDir, filename), Path.Combine(newDir, filename)));
}