I'm trying to be able to create several sub-folders within a folder on the main path I have already created, but I get a message saying the folder I'm trying to "cd" isn't valid. I would appreciate if someone could explain why this is happening, and either help me fix my cd code or give me an alternative way to access this folder.
This is for MATLAB 2019. I'm trying to get the code to auto-generate a folder with the date and time (which you can see in the first line below), and then create a sub-folder "Participant 1" (i.e. when you double click on the date and time, you open the sub-folder "Participant 1"). I then want to add a further sub-folder, "EMG_Data". I'm getting stuck at the point where I have to cd for the folder that has the currDate and "Participant 1" in it. As stated above, I would like to be able to create an additional sub-folder called "EMG_Data" within the "Participant 1" sub-folder, but I don't know how to get to the "Participant 1" folder (presumably I would have to cd it) because I don't know how I'm supposed to format the date (currDate) within the cd or other functions.
currDate = strrep(datestr(datetime), ':', '_');
mkdir('SMC Project Data Collection')
cd('C:/Users/wynkoopp/Documents/MATLAB/SMC Project/SMC Project Data Collection/')
mkdir(currDate,'Participant 1')
cd('C:/Users/wynkoopp/Documents/MATLAB/SMC Project/SMC Project Data Collection/currDate/Participant 1/')
mkdir('EMG_Data')
% Want the 'currDate' above to always be integrated into cd function above
% at the end, since name of folder will vary
I expect to have the subfolder 'EMG_Data' formed in the subfolder 'Participant 1', but this is not happening. Instead, I get:
Error using cd
Cannot CD to C:\Users\wynkoopp\Documents\MATLAB\SMC Project\SMC Project Data
Collection\currDate\Participant 1 (Name is nonexistent or not a directory).
Error in Paulcopydirectorygenerator (line 5)
cd('C:/Users/wynkoopp/Documents/MATLAB/SMC Project/SMC Project Data
Collection/currDate/Participant 1/')
The line mkdir(currDate,'Participant 1') create a folder in the folder with the current date. Your cd command tries to access to another folder which does not contain the current date.
Related
How can I allow user to add additional dependenies after the source code was compiled with mcc.
I was thinking about an empty folder next to the executable, where the users can add the needed .mat-files, but I can't add the folder path to my executable (since addpath is not allowed in deployed applications).
Any ideas?
This answer assumes that your code can be customised by data contained in one or more .mat files at runtime.
You can point your code to look at a folder where the optional .mat file(s) would be located.
For example in the users home folder with a sub folder being the name of your application (or in the local app data) or whereever...
If you want it in a sub folder where the exe is, you can do this as well, you find the exe path using (on windows):
[status, result] = system('path');
installpath = char(regexpi(result, 'Path=(.*?);', 'tokens', 'once'));
fprintf ( 'The exe install path is "%s"\n', installpath );
Then your code looks to load for example:
file2load = fullfile ( installpath, 'subFolder', 'runtimeCustomisation.mat' )
if exist ( file2load, 'file' ) == 2
"doSomething with the file"
end
Or something like that.
Recall that this is for dependencies which are .mat files only.
I'm creating a script to automatically copy and paste bookmarks to x amount of computers.
Robocopy the Mozilla Bookmarks which are stored in a file called places.sqlite on a drive. To the destination
Appdata\Roaming\Mozilla\Firefox\Profiles\\*RANDOM PROFILE NAME\places.sqlite
I can't find a solution to copy this file to the destination due to every windows profile and computer gets a random profile name created. I tried with a star * as you can see in the code because I thought a star choices the newest folder (last changed).
The code is:
$env:homeshare
$env:username
Robocopy "$env:homeshare\ComputerChange\" "C:\Users\$env:username\AppData\Roaming\Mozilla\Firefox\Profiles\*\" "places.sqlite" /COPY:DAT
How do I edit the code so it chooses the random named folder? Is it possible to copy the places.sqlite to ALL folder in the Profiles\ folder?
Appreciate the help
I work for a financial institution that pulls reports from out an outside source. I have an extremely basic batch file that checks folders for any zip file, extracts them to a different location, and moves the zip file to an "old" folder after extraction.
"C:\Program Files\WinZip\WZUNZIP.EXE" -d -o -sXXXXXXXXX C:\SFTP\ReportingAnalytics\Accounting\*.zip \\servername\Share2\Reporting_Analytics\Accounting\
MOVE C:\SFTP\ReportingAnalytics\Accounting\*.zip C:\SFTP\ReportingAnalyticsOld\Accounting
During the week, this works great. The problem is occurring on the weekends. These reports come over daily...unfortunately, with the same file name each day. So during the week, someone is working the report and there is no problem. On the weekends, no one works the report and they are getting overwritten (Friday's report comes in Saturday morning, gets overwritten on Sunday when Saturday's report comes in).
Is there an easy way to automatically rename these files upon extraction? ie AccountingReport1, AccountingReport2, and so on...
Any help would be greatly appreciated.
#ECHO OFF
SETLOCAL
SET "sourcedir=U:\sourcedir\one"
FOR %%a IN ("%sourcedir%\*.zip") DO (
ECHO("C:\Program Files\WinZip\WZUNZIP.EXE" -d -o -sXXXXXXXXX C:\SFTP\ReportingAnalytics\Accounting\%%a \\servername\Share2\Reporting_Analytics\Accounting\%%~na\
)
GOTO :EOF
You would need to change the setting of sourcedir to suit your circumstances.
The required WZUNZIP commands are merely ECHOed for testing purposes. After you've verified that the commands are correct, change ECHO("...WZUNZIP to "...WZUNZIP to actually create the directories and extract the files.
You don't tell us how many files/directories are in the archive or indicate their names, and your use of -d -o implies there's a whole slough, hence this approach is to extract each .zip file to a new directory, nameofzip under \\servername\S...s\Accounting
example
There is a file "sample.rar".
Folder structure is: "rising\dawn\ and here there are many (folders1, folders2 and file1, file2)" in this archive.
i have used following command
7z.exe x "sample.rar" "rising\dawn\*" -oi:\delete
The result is:
all files and folders in "rising\dawn\" are extracted to "i:\delete" folder but the empty parent folders "rising\dawn\" are also created in destination folder.
e.g. destination looks:
i:\delete\rising\dawn\folder1\file1.bmp
i:\delete\rising\dawn\folder2\subfolder
i:\delete\rising\dawn\file1.txt
i:\delete\rising\dawn\file2.txt
i don't want "rising\dawn\" empty folders to be created but the folder structure there onwards must be as is in the archive.
i want the result:
i:\delete\folder1\file1.bmp
i:\delete\folder2\subfolder
i:\delete\file1.txt
i:\delete\file2.txt
at last i found a way out solution. thanks to the winrar support. i have accepted it as an answer below.
if you find the question useful don't forget to click the up-vote button.
Finally this gave me the result.
Thanks to winrar support.
rar x -ep1 sample.rar rising\dawn\* d:\e\delete\
i have tried other answers given here, this is the only correct answer.
don't forget to upvote.
You can extract the archive normally and
1) move the lower level folder/files to where you would like it, then
2) remove the extra top level archive folders.
Code to do so will depend on the exact task.
Using e command instead of x and add -r option works well.
Like this:
7z.exe e -r "sample.rar" "rising\dawn\*" -oi:\delete
My executable version is "7-Zip [64] 9.20 2010-11-18",
And the platform is Windows 8.1.
This command line eliminates unnecessary parent folders and preserves the hierarchy of folders.
You need to use the e command rather than the x command:
7z.exe e "sample.rar" "scholar\update\*" -oi:\delete
Using e instead of x means 7zip will extract all matching files into the same folder (as specified via the -so switch, or the current directory if this isn't specified) rather than preserving the folder structure from inside the archive.
After executing some simple commands like
dos('copy *.txt new.txt', '-echo')
dos('echo. 2 > EmptyFile.txt', '-echo')
I tried to delete the folder in which these files were created. However, Windows gives me the message
"cannot delete "FolderName": the folder is being used by another person/program".
I have to close Matlab to make it work.
How do I solve this? I guess it's something like closing the "session" of cmd commands...
What you're not showing is the change of working directory to your folder. Windows won't let you delete a folder that a process has as a current working directory.
The solution is simple: change the working directory out of that folder. Say:
cd('..')