I am retrieving a list of items in a directory with fs.readdirSync(somePath). In this directory there are subdirectories or links to other directories.
/somePath/
- P13
- P31.lnk
- P46
- someOther.file
In each of the product folders there is a config.xml which I need to retrieve. I have filtered/mapped the list to either get ['P13', 'P31.lnk', 'P46'] or ['P13', 'P31', 'P46']. I need the real path to every config file (to read it with fs.readFileSync).
For P13 and P46 this is easy, but I'm struggling with P13. I tried several things with fs.realpathSync():
fs.realpathSync('/someDir/P13/config.xml')
fs.realpathSync('/someDir/P13.lnk')
fs.realpathSync('/someDir/P13')
Which all yield either an error or just the path of the link file, but don't follow the link. Is there any way in JS/Node to follow these links through? I need to do this on Windows, if this makes a difference.
Cheers and thanks
Related
I want to sync two different directories using the dirsync module, but exclude some specific folders.
In the documentation (https://pypi.org/project/dirsync/) it says the exclude need to be a regex pattern but I cant quite make it work.
For example, lets say we have these directories
c:\folder1\folder2
c:\folder1\folder3
d:\folder1\
I want to sync c:\folder1\ with d:\folder1\ and exclude folder3, so basically the folder c:\folder1\folder2 will be copied and created in d:\
from dirsync import sync
src = r'c:\folder1'
dst = r'd:\folder1'
sync(src, dst, 'diff', exclude='^folder3')
this won't work and I can't quite understand why.
The exclude option expects a list of regexp:
exclude=['^folder3']
I'm setting up a new algorithm and I want to share it on another computer. How can I set paths with only the folder name, for example.
I've tried to use the function os.chdir(path), but I don't achieve to reach my folder when I'm not using a 'root path' like C:/../../folder.
os.chdir(../folder_name)
By doing os.chdir(../folder_name), you are referring to the parent dir of the current directory.
You probably are looking for the os.chdir(./folder_name), with one dot? This is the current directory, where your script stands.
More here: https://learn.microsoft.com/en-us/dotnet/standard/io/file-path-formats
Update: After clarification in the comments, you want to refer to folder_name from one of its subfolder (/folder_name/library). Then it is indeed .. that you should use, but .. only:
os.chdir(..)
Is it possible to create dirs(folders) on cx_freeze build output, cause i include(include_files) many databases files and i want these to be in specific folder etc. I can take them easily from my folders.....
"include_files": ["databases/nations.txt","databases/newafrica.txt",
"databases/neweeurope.txt","databases/neweurope.txt","databases/newmeast.txt","graph.py",
"databases/newnamerica.txt","databases/plates.txt",
"databases/ACN/rigidA.txt","databases/ACN/rigidB.txt",
"databases/ACN/rigidC.txt","databases/ACN/rigidD.txt","databases/ACN/flexibleA.txt",
"databases/ACN/flexibleB.txt","databases/ACN/flexibleC.txt",
"databases/ACN/flexibleD.txt","alternates.xlsx",
but this will just copy all of them in exe build dir and its a mess.
Thanks in advance.
There are several ways you can go around solving the problem.
Method 1 - Using include_files
Rather than ask for each individual text file you could just put the file name in the setup script and leave out the individual text files. In your case it would be like this:
"include_files": ["databases"]
This would copy the entire databases folder with everything in it into you build folder.
Absolute file paths work as well.
If you are going to use the installer feature (bdist_msi) this is the method to use.
You can copy sub folders only using "include_files": ["databases/ACN"]
Method 2 - Manually
Ok it's rather un-pythonic but the one way to do it is to copy it manually into the build folder.
Method 3 - Using the os module
Much the same as method two it would copy the folder into your build folder but instead of coping it manually it would use Python. You also have the option of using additional Python features as well.
Hope I was helpful.
I have the following directories tree:
- client
- plugins
- plugin1
- plugin2
- plugin3
- widgets
- widget1
- widget2
- resources
- img
I need to copy all files from resources belonging to any particular plugin widget into one folder using grunt copy, so I'm using the following globbing pattern to find those files:
src: 'client/plugins/**/*/resources/img/*'
But it doesn't seem to be able to find them, so I guess the pattern is wrong. Where is my mistake?
I don't think you can use a specific directory after using the ** pattern because that already matches any subfolder. I think you'll need to be more specific:
src: 'client/plugins/*/widgets/*/resources/img/*'
If you can't use "widgets" exactly, then you'll need to find another alternative, maybe just using another /*/. You can find all of the globbing options in the node-glob Github repo README file. This includes things like anti-patterns if it comes to that.
I'm trying to store whole the output of my build, this includes some empty folders. These aren't included by the artefact mechanism in teamcity:
What doesn't work:
OAR\=> OAR.zip
OAR->OAR.zip
OAR
Inside of OAR i have a folder structure that needs to be stored. I know i could put a placeholder file in each but that is not the answer i'm after. Otherwise ill have to zip it myself?
Unfortunately TeamCity, by design, searches for files and uploads them as artifacts which means that empty folders are never included. Given the open and very old issue in the TeamCity tracker I doubt they are going to fix it any time soon.
I would recommend zipping the folder yourself, that is the approach we have taken. How you implement that depends on the build technology you are using. For example, if you are building using Nant you could add the zip task to your build, there are similar options for MSBuild and Ant.
If you don't want to rely on the build performing the zip I would recommend installing 7zip on your build agents and using the command line to perform the zip. Just remember if you want 7zip to include empty directories use * as the wildcard rather than *. * like so:
7z a -r OAR.zip *
Technically you could use powershell to do the zipping, which would be better than having to install something on your agents. I haven't tried this option myself.
Apologies for not linking all my references above. Apparently, and understandably so, I need at least 10 reputation to post more than 2 links.